js 手机号码合法性验证代码
var Mobile = $("#varMobilePhone").val();
var Phone = $("#varPhoneNo").val();
if (Mobile == ""&&Phone == "")
{
alert("手机和固话,请至少填写一项联系方式!");
$("#varMobilePhone").focus();
return;
}
if(Mobile!="")
{
if(!isMobil(Mobile))
{
alert("请输入正确的手机号码!");
$("#varMobilePhone").focus();
return; }
}
//手机号码验证信息
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; }
后台验证如下:
if (model.Zip != null)
{
if (!Common.PageValidate.IsValidate(model.Zip,"^\\d{6}$"))
{ Common.WebMessage.showMsg(HttpContext.Current, "请输入正确邮编");
return;
}
}
if (model.PhoneNo != null)
{
if (!Common.PageValidate.IsValidate(model.PhoneNo, "\\d{3}-\\d{8}|\\d{4}-\\d{7}"))
{
Common.WebMessage.showMsg(HttpContext.Current, "请输入正确的电话号码!");
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, "请输入正确11位有效的手机号码!");
return;
}
}