First one:
function Checkreg()
{
//Verification 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, the phone number you entered is wrong. Please separate the area code and phone number Split with -');
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 people, maximum 8 people
Second:
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; }
The background 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 valid digits phone number! ");
return;
}
}