<script type="text/javascript">
/* <![CDATA[ */
jQuery(function(){
jQuery("#ValidNumber").validate({
expression: "if (!isNaN(VAL) && VAL) return true; else return false;",
message: "Should be a number"
});
jQuery("#Email").validate({
expression: "if (VAL.match(/^[^\\W][a-zA-Z0-9\\_\\-\\.]+([a-zA-Z0-9\\_\\-\\.]+)*\\@[a-zA-Z0-9_]+(\\.[a-zA-Z0-9_]+)*\\.[a-zA-Z]{2,4}$/)) return true; else return false;",
message: "Should be a valid Email id"
});
jQuery("#ValidNumber").validate({
expression: "if (VAL > 100) return true; else return false;",
message: "Should be greater than 100"
});
jQuery("#Mobile").validate({
expression: "if (VAL.match(/^[9][0-9]{9}$/)) return true; else return false;",
message: "Should be a valid Mobile Number"
});
});
/* ]]> */
</script>
实际上这是我的jquery脚本问我如何在我按下表格中的重置按钮时,如何重置验证以及文本字段。
答案 0 :(得分:0)
将验证代码捆绑到一个这样的验证调用中时:
window.validator = $('form#your_formid').validate({
rules: {
validNumber: {
expression: "if (!isNaN(VAL) && VAL) return true; else return false;"
},
email: {
required: true,
email: true
},
// ...
},
messages: {
validNumber: {
expression: 'Should be a number'
},
email: {
required: 'Fill in your email,
email: 'Valid email please'
}
}
单击重置按钮
时,可以在de validate对象上调用resetFormwindow.validator.resetForm();