jQuery validate plugin : accept letters only?

I'm using the validate plugin from http://bassistance.de/jquery-plugins/jquery-plugin-validation/

What i'm trying to find is a way to make some of my form fields accept letters only, no numbers, special chars etc...

Any idea people ? Thanks a lot.


Simply add a custom validator, and use it like this:

jQuery.validator.addMethod("accept", function(value, element, param) {
  return value.match(new RegExp("." + param + "$"));
});

Only numbers:

rules: {
  field: { accept: "[0-9]+" }
}

Only letters

rules: {
  field: { accept: "[a-zA-Z]+" }
}

A small change.

jQuery.validator.addMethod("accept", function(value, element, param) {
    return value.match(new RegExp("^" + param + "$"));
});

Because that way it was accepting expressions like "#abc".