I. Related code
1 function test ()
2 {
3 var temp = document. getElementById ("text1 ");
4 // email Verification
5 var myreg =/^ ([a-zA-Z0-9] + [_ | \.]?) * [A-zA-Z0-9] + @ ([a-zA-Z0-9] + [_ | \.]?) * [A-zA-Z0-9] + \. [a-zA-Z] {2, 3} $ /;
6 if (! Myreg. test (temp. value ))
7 {
8 alert ('prompt \ n please enter a valid E_mail! ');
9 myreg. focus ();
10 return false;
11}
12}
13 // because the methods are the same, write only the relevant Regular Expressions
14 // verify the mobile phone number (two methods are provided)
15 var mobile =/^ (13 [0-9] {1}) | 159 | 153) + \ d {8} $ /;
16 var mobile1 =/^ (13 + \ d {9}) | (159 + \ d {8}) | (153 + \ d {8}) $ /;
17 // area code verification
18 var phoneAreaNum =/^ \ d {3, 4} $ /;
19 // verify the phone number
20 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 numeric character, which is equivalent to [0-9]