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
You can use the lettersonly
rule :) The additional methods are part of the zip you download, you can always find the latest here.
Here's an example:
$("form").validate({
rules: {
myField: { lettersonly: true }
}
});
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");
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…