Use JS Regular expression to verify mobile phone number, email address, zip code _javascript skills

Source: Internet
Author: User

Mobile phone number verification (13 opening and 158,159 beginning, total 11 digits)

Copy Code code as follows:

var re;
var Ss=document.getelementbyid (' TextBox3 '). Value;
Re=/^ (13[0-9]{9}) | (15[89][0-9]{8}) $/
if (Re.test (ss))
{
document.getElementById (' Label3 '). innertext= ""; Assign value to label with InnerText
}
Else
{
document.getElementById (' Label3 '). innertext= "Please enter the correct cell phone number!" ";
document.getElementById (' ImageButton1 '). Disabled=true; Disable button with disabled
}

Verification of the mail address (contains @ and.)
Copy Code code as follows:

var re;
var Ss=document.getelementbyid (TEXTBOXID). value;
Re=/\w@\w*\.\w/
if (Re.test (ss))
document.getElementById (' Label4 '). innertext= "";
Else
{
document.getElementById (' Label4 '). innertext= "Please enter the correct email address!" ";
document.getElementById (' ImageButton1 '). Disabled=true;
}

Verification of ZIP/Postal code (cannot start with 0, total 6 digits)
Copy Code code as follows:

var Ss=document.getelementbyid (' TextBox4 '). Value;
var re=/^[1-9][0-9]{5}$/
if (Re.test (ss))
document.getElementById (' Label5 '). innertext= "";
Else
{
document.getElementById (' Label5 '). Innertext= postal Code is not in the correct format! ";

}

var r=/^13[012345789]{9}/11 digits beginning with 13 and the number 6 cannot be found after 9 digits

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.