更新时间:2023-02-21 12:07:54
If you include the additional methods file, here's the current file for 1.7: http://ajax.microsoft.com/ajax/jquery.validate/1.7/additional-methods.js
您可以使用lettersonly
规则:)其他方法是您下载的zip文件的一部分,您始终可以找到最新的
You can use the lettersonly
rule :) The additional methods are part of the zip you download, you can always find the latest here.
这是一个例子:
$("form").validate({
rules: {
myField: { lettersonly: true }
}
});
值得注意的是,每个其他方法都是独立的,您可以包括该特定方法,只需将其放在您的.validate()
调用之前:
It's worth noting, each additional method is independent, you can include that specific one, just place this before your .validate()
call:
jQuery.validator.addMethod("lettersonly", function(value, element) {
return this.optional(element) || /^[a-z]+$/i.test(value);
}, "Letters only please");