Home >Web Front-end >JS Tutorial >JavaScript determines whether the email and mobile phone format entered by the user is correct_javascript skills

JavaScript determines whether the email and mobile phone format entered by the user is correct_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:10:262070browse
Copy code The code is as follows:

/*
* Function: Determine whether the email format entered by the user is Correct
* Parameters passed: None
* Return value: true or false
*/
function form_check() {
var email = document.getElementById("email").value; / /Get email address
//Judge whether the email format is correct
if(!/^w ([- .]w )*@w ([-.]w )*.w ([-.]w ) *$/.test(email)) {
alert("Email format error!");
document.getElementById("email").focus(); //Let the email text box get focus
return false;
}
return true;
}
/*
* Function: Determine whether the format of the mobile phone number entered by the user is correct
* Parameters passed: None
* Return Value: true or false
*/
function checkMobile(s) {
var regu = /^[1][0-9][0-9]{9}$/;
var re = new RegExp(regu);
if (re.test(s)) {
return true;
} else {
return false;
}
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn