$(document).ready(function() {
$.validator.addMethod("regex", function(value, element, regexpr) {
return regexpr.test(value);
}, "Please enter a valid code.");
$("#inputForm").validate({
rules:{
componentCode:{
required:true,
rangelength:[6-30],
regex:/[a-zA-Z0-9]{6,30}/,
/* regex: /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$/ */
}
},
messages:{
componentCode:{
required:'子件号码不能为空',
rangelength:'请输入{6}-{30}位字母或者数字',
regex : '密码必须是数字和字母组合'
}
},
submitHandler: function(form){
loading('正在提交,请稍等...');
form.submit();
},
errorContainer: "#messageBox",
errorPlacement: function(error, element) {
$("#messageBox").text("输入有误,请先更正。");
if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
error.appendTo(element.parent().parent());
} else {
error.insertAfter(element);
}
}
});