Verify that the account is legal
. Verification rules: letters, numbers, and underscores, starting with a letter, 4-16 digits.
function checkUser(str){ var re = /^[a-zA-z]\w{3,15}$/; if(re.test(str)){ alert( "correct" ); }else{ alert( "error" ); } } checkUser("jihua_cnblogs "); // call
Verify mobile phone number
verification rules: 11 digits, starting with 1.
function checkMobile(str) { var re = /^1\d{10}$/ if (re.test(str)) { alert( "correct" ); } else { alert( "error" ); } } checkMobile( '13800138000'); // call checkMobile('139888888889'); // error example
Verify phone number
verification rules: area code + number, the area code starts with 0, and the 3-digit or 4-digit
number consists of 7 or 8 digits.
There can be no connector between the area code and the number, or a "-" connection
such as 01088888888,010- 88888888,0955-7777777
function checkPhone(str){ var re = /^0\d{2,3}-?\d{7,8}$/; if(re.test(str)){ alert( "correct" ); }else{ alert( "error" ); } } checkPhone( "09557777777"); // call
Verifying the email
verification rules: Let's divide the email address into "Part 1@Part 2" so that
the first part: consists of letters, numbers, underscores, dashes "-", dots ".", and
the second part: a domain name, a domain name It consists of letters, numbers, short lines "-", and domain name suffixes.
The domain name suffix is generally .xxx or .xxx.xx. The domain name suffix of a zone is generally 2-4 digits, such as cn, com, and net. Now there are some domain names. will also be greater than 4 digits
function checkEmail(str){ var re = /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/ if(re.test(str)){ alert( "correct" ); }else{ alert( "error" ); } } checkEmail( " [email protected] "); // call
Web front-end summary : http://www.cnblogs.com/jihua/p/webfront.html