Skip to content

isAlphanumeric ​

The isAlphanumeric function checks if a string contains only alphanumeric characters (letters and numbers), without symbols or spaces.

Syntax ​

javascript
isAlphanumeric(value)

Parameters ​

ParameterTypeDescription
valuestringThe string to be checked.

Return ​

TypeDescription
booleanReturns true if the string contains only letters and numbers, otherwise returns false.

Examples ​

javascript
isAlphanumeric('abc123');   // true
isAlphanumeric('ABC');      // true
isAlphanumeric('123');      // true
isAlphanumeric('abc!');     // false
isAlphanumeric('abc 123');  // false
isAlphanumeric('');         // false

Notes ​

  • Throws a TypeError if the provided value is not a string.
  • Does not allow spaces, accents, or symbols.

References ​

Released under the MIT License.