Verify the account, mobile phone number, phone number, and email address using the JS regular expression.

Source: Internet
Author: User

Verify that the account is valid
Verification rules: a combination of letters, numbers, and underscores. It must start with a letter and contain 4-16 characters.

 
FunctionCheckuser (STR ){VaRRe=/^ [A-Za-Z] \ W {3, 15} $/;If(Re. Test (STR) {alert ("Correct");}Else{Alert ("Error") ;}} Checkuser ("jiade_cnblogs");//Call

 

Verify mobile phone number
Verification rules: 11-digit number, starting with 1.

FunctionCheckmobile (STR ){VaRRe=/^ 1 \ D {10} $/If(Re. Test (STR) {alert ("Correct");}Else{Alert ("Error") ;}} Checkmobile ('123 ');//CallCheckmobile ('20140901 ');//Error example

 

Verify phone number
Verification rules: area code + number. The area code starts with 0 and has three or four digits.
The number consists of seven or eight digits.
There can be no connector or "-" connection between the area code and the number.
For example, 01088888888,010-888888,0955-7777777

FunctionCheckphone (STR ){VaRRe=/^ 0 \ D {2, 3 }-? \ D {7, 8} $/;If(Re. Test (STR) {alert ("Correct");}Else{Alert ("Error") ;}} Checkphone ("09557777777 ");//Call

 

Verify email
Verification rules: divide the email address into "first part @ second part ".
The first part is composed of letters, numbers, underscores, short-term "-", and period,
The second part is a domain name, which consists of letters, numbers, short-term "-", and domain name suffixes,
The domain name suffix is generally. xxx or. XXX. XX. The domain name suffix of a region is generally 2-4 characters, such as CN, COM, and net. Now some domain names will be larger than 4 characters

FunctionCheckemail (STR ){VaRRe=/^ (\ W-* \. *) + @ (\ W -?) + (\. \ W {2,}) + $/If(Re. Test (STR) {alert ("Correct");}Else{Alert ("Error") ;}} Checkemail ("Contact@cnblogs.com");//Call

 

 

Modified from: http://blog.csdn.net/bkq421511585/article/details/8027445

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.