/Verify that the account is legal
Validation rules: Letters, numbers, underscores, letters beginning with 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
Mobile phone number
Validation rule: 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
Phone number
Validation rules: Area code + number, area code starting with 0, 3-bit or 4-bit
Numbers are made up of 7-bit or 8-digit numbers
There can be no connector between the area code and the number, or a "-" connection
function
Checkphone (str) {
Var
re =/^0\d{2,3}-?\d{7,8}$/;
if (Re.test (str)) {
Alert ("correct");
}else{
Alert ("Error");
}
}
Checkphone ("09557777777");//Call
Mailbox
Validation rules: Leave your email address in the "first part @ Second part"
The first part: By letter, number, underline, short line "-", Dot "." Composition
Part two: For a domain name, the domain name consists of letters, numbers, short-term "-", the domain name suffix,
and the domain name suffix is generally. xxx or. xxx.xx, a domain name suffix is generally 2-4-bit, such as cn,com,net, now the domain name will be more than 4 bit
function
Checkemail (str) {
Var
Re =/^ (\w-*\.*) [email protected] (\w-?) + (\.\w{2,}) +$/
if (Re.test (str)) {
Alert ("correct");
}else{
Alert ("Error");
}
}
Checkemail ("[email protected]");//Call
JS Regular expression verification account, mobile phone number, phone, and e-mail