jquery validation 简单验证手机号码

js代码

 1   // 手机号码验证
 2         jQuery.validator.addMethod("isMobile", function(value, element) {
 3             var length = value.length;
 4             var mobile = /^(1)\d{10}$/;
 5             return this.optional(element) || (length == 11 && mobile.test(value));
 6         }, "请正确填写手机号码");
 7 
 8 $("#jsForm").validate({
 9 
10             focusInvalid: false,
11             submitHandler: function (form) {
12 
13                 form.submit();
14             }
15         });

 

Html 部分

1   <div class="form-group">
2                         <div class="col-lg-2  control-label text-right">手机</div>
3                         <div class="col-lg-10">
4                             <input type="text" class="form-control" name="cell_phone"
5                                    value="<?= $data['cell_phone'] ?>"  required data-rule-isMobile="true"  data-msg-required="*手机号不能为空">
6                         </div>
7                     </div>

 

posted @ 2016-11-09 15:38  哦先生  阅读(7607)  评论(0编辑  收藏  举报