Home  >  Article  >  Web Front-end  >  js mobile phone number legality verification code collection_javascript skills

js mobile phone number legality verification code collection_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:49:361370browse

First code:

Copy code The code is as follows:

function Checkreg()
{
//Verify phone number mobile phone number, including 153, 159 segments
if (document.form.phone.value=="" && document.form.UserMobile.value=="") {
alert("Please fill in at least one phone number and mobile phone number!");
document.form.phone.focus();
return false;
}
if (document .form.phone.value != ""){
var phone=document.form.phone.value;
var p1 = /^(([0 ]d{2,3}-)?(0d {2,3})-)?(d{7,8})(-(d{3,}))?$/;
var me = false;
if (p1.test(phone) )me=true;
if (!me){
document.form.phone.value='';
alert('Sorry, there is an error in the phone number you entered. Between the area code and the phone number Please use - to split');
document.form.phone.focus();
return false;
}
}
if (document.form.UserMobile.value != "" ){
var mobile=document.form.UserMobile.value;
var reg0 = /^13d{5,9}$/;
var reg1 = /^153d{4,8}$/;
var reg2 = /^159d{4,8}$/;
var reg3 = /^0d{10,11}$/;
var my = false;
if (reg0.test (mobile))my=true;
if (reg1.test(mobile))my=true;
if (reg2.test(mobile))my=true;
if (reg3.test(mobile ))my=true;
if (!my){
document.form.UserMobile.value='';
alert('Sorry, the mobile phone or PHS number you entered is wrong. ');
document.form.UserMobile.focus();
return false;
}
return true;
}
}

Description
The test method checks whether a pattern exists in the string and returns true if it exists, otherwise it returns false.

Regular expression part:
d represents a number
{7,8} represents 7-8 digits (representing a phone number)
{3,} represents an extension number
d{2,3} represents the area code
]d{2,3} represents the international area code
^13d{5,9}$/ //130?139. At least 5 people, at most 9 people
/^153d{4,8}$/ //China Unicom 153. At least 4 digits, at most 8 digits
/^159d{4,8}$/ //Move 159. At least 4 digits, up to 8 digits

Second one:
Copy code The code is as follows:

var Mobile = $("#varMobilePhone").val();
var Phone = $("#varPhoneNo").val();
if (Mobile == ""&&Phone = = "")
{
alert("Mobile and landline, please fill in at least one contact information!");
$("#varMobilePhone").focus();
return;
}
if(Mobile!="")
{
if(!isMobil(Mobile))
{
alert("Please enter the correct mobile phone number!");
$("#varMobilePhone").focus();
return; }
}
//Mobile phone number verification information
function isMobil(s)
{
var patrn = /(^0{0,1}1[3|4|5|6|7|8|9][0-9]{9}$)/;
if (!patrn.exec(s ))
{
return false;
} return true; }
Backend verification is as follows:
if (model.Zip != null)
{
if (!Common .PageValidate.IsValidate(model.Zip,"^\d{6}$"))
{ Common.WebMessage.showMsg(HttpContext.Current, "Please enter the correct zip code");
return;
}
}
if (model.PhoneNo != null)
{
if (!Common.PageValidate.IsValidate(model.PhoneNo, "\d{3}-\d{8}| \d{4}-\d{7}"))
{
Common.WebMessage.showMsg(HttpContext.Current, "Please enter the correct phone number!");
return;
}
}
if (model.MobilePhone != null)
{
if (!Common.PageValidate.IsValidate(model.MobilePhone, "^0{0,1}(13[0- 9]|15[3-9]|15[0-2]|18[0-9])[0-9]{8}$"))
{
Common.WebMessage.showMsg(HttpContext .Current, "Please enter the correct 11-digit valid mobile phone number! ");
return;
}
}
Statement:
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