This article mainly introduces the format of the JS Regular Expression verification mailbox. If you need some help, you can refer to it and hope to help us with WEB development. form verification is essential, so today we will list some common verification items, I hope you can criticize and correct the JS regular expression I just learned this afternoon.
I. Related code
The Code is as follows:
Function test ()
{
Var temp = document. getElementById ("text1 ");
// Email Verification
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 ('prompt/n please enter a valid E_mail! ');
Myreg. focus ();
Return false;
}
}
// Because the methods are the same, write only the relevant Regular Expressions
// Verify the 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}) $ /;
// Area code verification
Var phoneAreaNum =/^/d {3, 4} $ /;
// Verify the phone number
Var phone =/^/d {7, 8} $ /;
}
Ii. Explanations
1./^ $/This is a common format.
^ Match the start position of the input string; $ match the end position of the input string
2. Enter the functions to be implemented.
* Matches the previous subexpression zero or multiple times;
+ Match the previous subexpression once or multiple times;
? Match the previous subexpression zero or one time;
/D matches a digit, which is equivalent to [0-9].