jquery.validator 手機號驗證


1.在input中加上mobile="true",maxlength="11"   

<label class="w170 control-label floatL">&nbsp;&nbsp;聯系電話 &nbsp;</label>
            <div class="col-sm-3 lc_chargeTitleM">
                <input type="text" name="Phone" id="Phone"  value="" mobile="true" maxlength="11" class="form-control"/>
            </div>

2.jauery.validator手機號驗證,驗證不通過提示“手機號碼格式錯誤”

$(function () {
        //正則表達式
        jQuery.validator.addMethod("mobile", function (value, element) {
            var length = value.length;
            var mobile = /^(13[0-9]|14[0-9]|15[0-9]|17[0-9]|18[0-9])[0-9]{8}$/;
            return this.optional(element) || (length == 11 && mobile.test(value));
        }, "手機號碼格式錯誤");
    }

 

2020.06.04
var phone = $("#phone").val();
    if (phone==""){
        layer.msg("請輸入手機號碼",{icon : 2});
        return
    }
    var testPhone = /^1(3|4|5|7|8|9)\d{9}$/;
    if(!testPhone.test(phone)){
        layer.msg("手機號輸入格式有誤,請重新輸入!",{icon:2});
        return;
    }

 


免責聲明!

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



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