Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check for alphanumeric characters

Tags:

jquery

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?

like image 787
AKor Avatar asked Apr 20 '11 14:04

AKor


People also ask

How do you check if a character is alphanumeric or not?

The isalnum() method returns True if all the characters are alphanumeric, meaning alphabet letter (a-z) and numbers (0-9). Example of characters that are not alphanumeric: (space)!

How do you know if an expression is alphanumeric?

For checking if a string consists only of alphanumerics using module regular expression or regex, we can call the re. match(regex, string) using the regex: "^[a-zA-Z0-9]+$".

What does alphanumeric characters look like?

Alphanumeric characters are the numbers 0-9 and letters A-Z (both uppercase and lowercase). An alphanumeric example are the characters a, H, 0, 5 and k. These characters are contrasted to non-alphanumeric ones, which are anything other than letters and numbers.


1 Answers

See test RegExp method.

jQuery.validator.addMethod("alphanumeric", function(value, element) {
        return this.optional(element) || /^[a-zA-Z0-9]+$/.test(value);
}); 
like image 110
Josiah Ruddell Avatar answered Oct 11 '22 18:10

Josiah Ruddell