JS Regular Expressions Verify Legal Account Number Mobile Phone Number Telephone Number and Mailbox
- 2021-08-03 08:10:27
- OfStack
Verify that the account is legal
Verification rules: letters, numbers, underscores, letters beginning, 4-16 digits.
function
checkUser(str){
var
re = /^[a-zA-z]\w{3,15}$/;
if(re.test(str)){
alert(" Correct ");
}else{
alert(" Errors ");
}
}
checkUser("jihua_cnblogs");// Call
Verify the 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(" Errors ");
}
}
checkMobile('13800138000'); // Call
checkMobile('139888888889');// Error example
Verify telephone number
Verification rule: Area code + number, area code beginning with 0, 3 or 4 digits
Numbers consist of 7 or 8 digits
Area code and number can have no connector or "-" connection
Such as 01088888888, 010-8888888, 0955-7777777
function
checkPhone(str){
var
re = /^0\d{2,3}-?\d{7,8}$/;
if(re.test(str)){
alert(" Correct ");
}else{
alert(" Errors ");
}
}
checkPhone("09557777777");// Call
Verify mailbox
Verification rule: Let's just divide the email address into "Part 1 @ Part 2"
Part 1: It consists of letters, numbers, underscores, short lines "-" and dots ".".
Part 2: It is a domain name, which consists of letters, numbers, short line "-" and domain name suffix.
The domain name suffix 1 is generally. xxx or. xxx. xx, and the domain name suffix 1 in Zone 1 is generally 2-4 digits, such as cn, com and net. Now some domain names are larger than 4 digits
function
checkEmail(str){
var
re = /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/
if(re.test(str)){
alert(" Correct ");
}else{
alert(" Errors ");
}
}
checkEmail("contact@cnblogs.com");// Call
Above is the site introduced to you JS regular expression to verify the account number, mobile phone number, telephone and mailbox is legal, I hope to help you, if you have any questions welcome to leave me a message, this site will reply to you in time!