Js validation form 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.
 
?
Function
CheckUser (str ){
Var
Re =/^ [a-zA-z] \ w {3, 15} $ /;
If (re. test (str )){
Alert ("correct ");
} Else {
Alert ("error ");
}
}
CheckUser ("q_11"); // call
 
2. Verify the mobile phone number
Verification rules: 11-digit number, starting with 1.
 
 
Function
CheckMobile (str ){
Var
Re =/^ 1 \ d {10 }/
If (re. test (str )){
Alert ("correct ");
} Else {
Alert ("error ");
}
}
CheckMobile (13900001111); // call
 
3. Verify the 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, 01012345678 010-12345678.
 
Function
CheckPhone (str ){
Var
Re =/^ 0 \ d {2, 3 }-? \ D {7, 8} $ /;
If (re. test (str )){
Alert ("correct ");
} Else {
Alert ("error ");
}
}
CheckPhone ("012312345678"); // call
 
4. 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
 
 
Function
CheckEmail (str ){
Var
Re =/^ (\ w-* \. *) + @ (\ w -?) + (\. \ W {2,}) + $/
If (re. test (str )){
Alert ("correct ");
} Else {
Alert ("error ");
}
}
CheckEmail ("s_test@test.cn"); // call

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.