Home > Web Front-end > JS Tutorial > body text

Use js regular expressions to verify mobile phone numbers, email addresses, and postal codes_javascript skills

WBOY
Release: 2016-05-16 17:02:45
Original
1452 people have browsed it

Verification of mobile phone number (starting with 13 and starting with 158, 159, 11 digits in total)

Copy code 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=""; //Give label Use innerText
}
else
{
document.getElementById('label3').innerText="Please enter the correct mobile phone number!";
document.getElementById('imagebutton1') .disabled=true; //Disable Button using disabled
}

Verification of email address (including @ and .)
Copy Code 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="Please enter the correct email address!";
document.getElementById('imagebutton1').disabled=true;
}

Postcode verification (the beginning cannot be is 0, 6 digits in total)
Copy code 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="The postal code format is incorrect! ";

}

var r= /^13[012345789]{9}/ 11 digits starting with 13, the number 6 cannot appear in the last 9 digits

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!