Use js regular expression to verify mobile phone number, email address, postal code _ javascript skills-js tutorial

Source: Internet
Author: User
Use the js regular expression to verify the mobile phone number, email address, and zip code. If you want to verify your mobile phone number, you can refer to it for reference. (11 digits are entered at the beginning of "13" and "158,159)

The Code is 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 a value to the label using innerText
}
Else
{
Document. getElementById ('label3'). innerText = "enter the correct mobile phone number! ";
Document. getElementById ('imagebutton1'). disabled = true; // disable disabled for Button
}


Verify the email address (including @ and .)

The Code is 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 = "enter the correct email address! ";
Document. getElementById ('imagebutton1'). disabled = true;
}


Zip code verification (cannot start with 0, 6 digits in total)

The Code is 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 = "Incorrect zip code format! ";

}

Var r =/^ 13 [012345789] {9}/11 digits starting with 13, the last 9 digits cannot contain 6 digits

Related Article

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.