//按钮先执行验证再提交表 $(document).ready(function(){ // 点击查看图片 $('.nyroModal').nyroModal(); //按钮先执行验证再提交表单 $("#submitBtn").click(function(){ if($("#add_form").valid()){ $("#add_form").submit(); } }); //自定义空格验证 $.validator.addMethod("spacing",function(value,element,param){ var reg = new RegExp("[\u4E00-\u9FFF]+","g"); var regshu = /[~#^$@%&!?%;;¥……::*]/gi; if(value.indexOf(' ')>0 || reg.test(value) || regshu.test(value)){ return false; }else{ return true; } }); $("#add_form").validate({
span.arr提示 errorPlacement: function(error, element){ var error_td = element.parent('dd').children('span.err'); error_td.append(error); }, rules : { admin_name : { required : true, minlength: 2, maxlength: 16, spacing : true, remote : { url :'index.php?act=teachermanager&op=ajax&branch=check_admin_name', type:'get', data:{ admin_name : function(){ return $('#admin_name').val(); } } } }, admin_password : { required : true, minlength: 6, maxlength: 32, spacing : true, }, admin_number : { required : true, minlength: 6, maxlength: 32, spacing : true, }, admin_rpassword : { required : true, equalTo : '#admin_password' }, gid : { required : true } }, messages : { admin_name : { required : '<i class="fa fa-exclamation-circle"></i>教师姓名不能为空', minlength: '教师姓名长度为2-16位。', maxlength: '教师姓名长度为2-16位。', remote : '<i class="fa fa-exclamation-circle"></i>教师姓名已存在', spacing:"请误输入空格、中文、特殊字符" }, admin_password : { required : '<i class="fa fa-exclamation-circle"></i>密码不能为空', minlength: '密码长度6-32个字符。', maxlength: '密码长度不超过32个字符。', spacing:"请误输入空格、中文、特殊字符" }, admin_number2 : { required : '<i class="fa fa-exclamation-circle"></i>教师编码不能为空', minlength: '教师编码长度6-32个字符。', maxlength: '教师编码不超过32个字符。', spacing:"请误输入空格、中文、特殊字符" }, admin_number : { required : '<i class="fa fa-exclamation-circle"></i>登录账号不能为空', minlength: '登录账号长度6-32个字符。', maxlength: '登录账号不超过32个字符。', spacing:"请误输入空格、中文、特殊字符" }, admin_rpassword : { required : '<i class="fa fa-exclamation-circle"></i>确认密码不能为空', equalTo : '<i class="fa fa-exclamation-circle"></i><?php echo $lang['admin_edit_repeat_error']; ?>' }, gid : { required : '<i class="fa fa-exclamation-circle"></i><?php echo $lang['admin_add_gid_null']; ?>' } } }); });