AKor AKor - 1 year ago 86
jQuery Question

How to check for alphanumeric characters

I'm writing a custom method for a jQuery plugin:

jQuery.validator.addMethod("alphanumeric", function(value, element) {
return this.optional(element) || (/*contains "^[a-zA-Z0-9]*$"*/);
});


I know the regexp for what I want, but I'm not sure how to write something in JS that will evaluate to True if it contains the alphanumeric characters. Any help?

Answer Source

See test RegExp method.

jQuery.validator.addMethod("alphanumeric", function(value, element) {
        return this.optional(element) || /^[a-zA-Z0-9]+$/.test(value);
}); 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download