JQuery uses regular expressions to verify mobile phone numbers, email addresses, ID cards (including Hong Kong, Macao and Taiwan(China)), and jquery Regular Expressions
I have never used the regular expression verification system. I made a demo this time and used it all at once. I will take it directly next time.
The following code uses JQuery for verification on the page, and is also used for verification in the background. You can try the same principle.
Directly run the Code:Note: (some verification rules are not only in this article, but may also be better. You can leave a message)
Mobile phone number: (mobile-Telecom-China Unicom)
Var tel = $ ("# PhoneNumber"). val (); // obtain the entered mobile phone number
Var yidongreg =/^ (134 [012345678] \ d {7} | 1 [34578] [012356789] \ d {8}) $ /;
Var dianxinreg =/^ 1 [3578] [01379] \ d {8} $ /;
Var liw.greg =/^ 1 [34578] [01256] \ d {8} $ /;
// Var reg =/^ 1 [3 | 4 | 5 | 7 | 8] \ d {9} $ /; //
If (yidongreg. test (tel) | dianxinreg. test (tel) | liw.greg. test (tel ))
{
}
Email:
Var emailvalue = $ ("# EmailUser"). val (); // obtain the input email address
// Var emailreg1 =/^ \ w + ([-+.] \ w +) * @ ("@") \ w + ([-.] \ w + )*\. \ w + ([-.] \ w +) * $/; // This can also be
Var emailreg =/^ \ w + (-\ w +) | (\. \ w +) * \ @ ("@") [A-Za-z0-9] + ((\. |-) [A-Za-z0-9] + )*\. [A-Za-z0-9] + $ /;
If (emailreg. test (emailvalue ))
{
}
ID card:
Var userCardvalue = $ ("# UserIDCard"). val (); // get the input ID card
Var userCardreg =/(^ \ d {15} $) | (^ \ d {18} $) | (^ \ d {17} (\ d | X | x) $ )/;
Var xianggangreg =/^ [A-Z] [0-9] {6} \ ([0-9A] \) $ /;
Var aomenreg =/^ [157] [0-9] {6} \ ([0-9] \) $ /;
If (userCardreg. test (userCardvalue) | test (userCardvalue) | xianggangreg. test (userCardvalue) | aomenreg. t est (userCardvalue ))
{
}
If you have any questions, you can leave a message. I usually view the message once a day. Thank you.