Bądź ostrożny,
jQuery.validator.addMethod("lettersonly", function(value, element)
{
return this.optional(element) || /^[a-z," "]+$/i.test(value);
}, "Letters and spaces only please");
[AZ ",„] dodając przecinek i cudzysłowu, pozwalasz obowiązuje , przecinki i cudzysłowy w polu wprowadzania.
do pomieszczeń + tekst, po prostu to zrobić:
jQuery.validator.addMethod("lettersonly", function(value, element)
{
return this.optional(element) || /^[a-z ]+$/i.test(value);
}, "Letters and spaces only please");
[A-Z] pozwala przestrzenie aswell jak tylko tekst.
.............................................. ..............................
także wiadomość "Tylko litery i spacje proszę" nie jest wymagana, jeśli już komunikat w wiadomościach:
messages:{
firstname:{
required: "Enter your first name",
minlength: jQuery.format("Enter at least (2) characters"),
maxlength:jQuery.format("First name too long more than (80) characters"),
lettersonly:jQuery.format("letters only mate")
},
Adama
^[A-Za-z] + $, aby również akceptować wielkie litery lub ustawić wartość na małe litery z funkcją toLowerCase(). –
przegłosowano dla 'this.optional (element) ||' – Pankaj