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;
     }
    }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM