For those of us doing WEB development, form verification is essential, so today I will list some commonly used verifications. Haha, I just learned the JS regular expressions this afternoon. I hope you have any shortcomings. Criticize and correct.
1. Relevant code
function test()
{
var temp = document.getElementById("text1");
//Verification of email
var myreg = /^([a-zA-Z0 -9] [_|/_|/.]?)*[a-zA-Z0-9] @([a-zA-Z0-9] [_|/_|/.]?)*[a- zA-Z0-9] /.[a-zA-Z]{2,3}$/;
if(!myreg.test(temp.value))
{
alert('hint/ n/nPlease enter a valid E_mail! ');
myreg.focus();
return false;
}
}
//Since the method is the same, only the relevant ones will be written here Regular expression
//Verification of mobile phone number (two methods are provided)
var mobile=/^((13[0-9]{1})|159|153) /d{8} $/;
var mobile1=/^(13 /d{9})|(159 /d{8})|(153 /d{8})$/;
//Verification of area code
var phoneAreaNum = /^/d{3,4}$/;
//Verification of phone number
var phone =/^/d{7,8}$/;
}
2. Explain the relevant meanings
1. /^$/ This is a general format.
^ matches the start position of the input string; $ matches the end position of the input string
2. Enter the function to be implemented.
* Matches the previous subexpression zero or more times;
Matches the previous subexpression one or more times;
? Matches the previous subexpression zero or once;
/d matches a numeric character, equivalent to [0-9]