jQuery验证插件-仅在检查变量后提交
我自己做了一些小验证,结果是-myvalid=true或mayvalid=false。如何使用验证插件将此检查添加到我正在表单上进行的验证中?您可以使用jQuery验证插件-仅在检查变量后提交,jquery,validation,variables,submit,Jquery,Validation,Variables,Submit,我自己做了一些小验证,结果是-myvalid=true或mayvalid=false。如何使用验证插件将此检查添加到我正在表单上进行的验证中?您可以使用.addMethod()将自定义验证方法添加到验证插件中 更新: 下面是一个您可以测试的示例: HTML +1-这真的是一条路要走,把它作为规则添加到你要检查的元素上。 <form id='theForm'> <input id='test_field' name='test_field' value='jQuery
.addMethod()
将自定义验证方法添加到验证插件中
更新: 下面是一个您可以测试的示例: HTML
+1-这真的是一条路要走,把它作为规则添加到你要检查的元素上。
<form id='theForm'>
<input id='test_field' name='test_field' value='jQuery' />
<br>
<input id='test_field2' name='test_field2' value='prototypejs' />
</form>
// Add a validation method to the validator plugin
// that can be applied as a rule to whatever fields
// you want. That way you get your custom validation
// integrated into the functionality of the plugin
$.validator.addMethod(
"mustIncludejQuery",
function(value, element) {
return value.toLowerCase().indexOf('jquery') > -1;
},
"You must type jQuery to be valid."
);
// Apply the custom validation to the fields
$('#theForm').validate({
rules: {
test_field:'mustIncludejQuery',
test_field2:'mustIncludejQuery'
}
});
// Demonstrates that they will be executed
// like any other validation rule.
$('#theForm').valid();