<!--editpanl start--> <div class="modal fade" id="editpanl" data-backdrop="static"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h4 class="modal-title">xxxxxxxxxx</h4> </div> <form role="form" id="form1" method="post" class="validate formvalidate"> <div class="modal-body"> <div class="form-group" style="margin: 0 auto; background-color: #F2F8FE;border: 1px solid #CCE5FF;padding: 0 10px 10px 10px;"> <h3 style="color: #4BA9E9;font-weight: bold;font-size: 14px;">温馨提示:</h3> <p style="font-size: 12px;">xxxxxxxxxxxxxxxx!</p> </div> <div class="row" style="margin-top: 20px;"> <div class="col-md-12"> <div class="form-group"> <label for="inputtel" class="control-label"><span class="required">*</span>xxxxxxxxxx</label> <input type="text" class="form-control" id="inputtel" name="inputtel" maxlength="11" placeholder=""/> </div> </div> <div class="col-md-12"> <div class="form-group"> <label for="inputcode" class="control-label"><span class="required">*</span>xxxxxxx</label> <input id="inputcode" name="inputcode" type="text" class="form-control" placeholder=""/> </div> </div> <div class="col-md-12"> <div class="form-group"> <label for="inputcarnum" class="control-label"><span class="required">*</span>xxxxxxxxx</label> <input id="inputcarnum" name="inputcarnum" type="text" class="form-control" placeholder=""/> </div> </div> <div class="col-md-12"> <div class="form-group"> <label for="cartype" class="control-label"><span class="required">*</span>xxxxxxxxx</label> <select class="form-control" id="cartype" name="cartype"> <option value="">--请选择--</option> <option value="1">xxxxxxxx</option> <option value="2">xxxxxxxx</option> </select> </div> </div> </div> </div> <div class="modal-footer"> <div class="modal-msg"></div> <button type="submit" class="btn btn-success" id="btnSave">保存</button> <button type="reset" class="btn btn-white" data-dismiss="modal">关闭</button> </div> </form> </div> </div> </div> <!--editpanl end-->
/** * 非空验证 * */ htmlObj.formvalidator = function(){ //表单验证 $(".formvalidate").validate({ debug:true, submitHandler:function() { htmlObj.save(); }, onfocusout: function(element) { $(element).valid(); }, rules: { inputtel: { required: true, isphone:true }, inputcode:{ required: true, maxlength:20, uniqueness:true }, cartype: { required: true }, inputcarnum: { required: true, maxlength:20 } }, messages: { inputtel: {required:"不能为空!"}, inputcode: { required:"不能为空!", maxlength:"长度不能超过20个字符"}, cartype: {required:"不能为空!"}, inputcarnum: { required:"不能为空!", maxlength:"长度不能超过20个字符"} } }); };
/** * 唯一性验证 * */ jQuery.validator.addMethod("uniqueness",function(){ var flag=1; var resname = $("#resname").val(); var parentid = $("#parentid").val() || "0"; var cmd = new Command('xxxx', 'xxxx', 'xxxxxxx'); cmd.id = htmlObj.id; cmd.rfidcode = $("#inputcode").val(); cmd.success = function(data) { if (data.state == 1){ if(data.isexist == 1){ flag=0; } } }; cmd.execute(); if (flag == 0) { return false; } else { return true; } },"已存在!");
jQuery.validator.addMethod("isphone", function(value, element) { var length = value.length; var regPhone = /^1([3578]\d|4[57])\d{8}$/; return this.optional(element) || ( length == 11 && regPhone.test( value ) ); }, "请正确填写您的手机号码");
来源:https://www.cnblogs.com/webgg/p/5508207.html