JS regular expression to verify account number, mobile phone number, phone number and email address, summary of the front part of the web

Verify that the account is legal
. Verification rules: letters, numbers, and underscores, starting with a letter, 4-16 digits.

copy code
function
 checkUser(str){
    var
 re = /^[a-zA-z]\w{3,15}$/;
    if(re.test(str)){
        alert( "correct" );
    }else{
        alert( "error" );
    }          
}
checkUser("jihua_cnblogs "); // call
copy code

 

Verify mobile phone number
verification rules: 11 digits, starting with 1.

copy code
function 
 checkMobile(str) {
    var 
 re = /^1\d{10}$/
    if (re.test(str)) {
        alert( "correct" );
    } else {
        alert( "error" );
    }
}
checkMobile( '13800138000'); // call 
checkMobile('139888888889'); // error example
copy code

 

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 

copy code
function
 checkPhone(str){
    var
 re = /^0\d{2,3}-?\d{7,8}$/;
    if(re.test(str)){
        alert( "correct" );
    }else{
        alert( "error" );
    }
}
checkPhone( "09557777777"); // call
copy code

 

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

copy code
function
 checkEmail(str){
    var
 re = /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/
    if(re.test(str)){
        alert( "correct" );
    }else{
        alert( "error" );
    }
}
checkEmail( " [email protected] "); // call
copy code

 

 Web front-end summary : http://www.cnblogs.com/jihua/p/webfront.html

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327017272&siteId=291194637
Recommended