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));
        }, "手机号码格式错误");
    }

 

猜你喜欢

转载自www.cnblogs.com/wl1202/p/10762066.html