486 B
486 B
title, tags
| title | tags |
|---|---|
| isAlphaNumeric | string,regexp,intermediate |
Checks if a string contains only alphanumeric characters.
Use String.prototype.match() to check if input string matches against alphanumeric regex pattern.
const isAlphaNumeric = (str) => !!str.match(/^[a-z0-9]+$/gi);
isAlphaNumeric('hello123'); // true
isAlphaNumeric('123'); // true
isAlphaNumeric('hello 123'); // false (space character is not alphanumeric)
isAlphaNumeric('#$hello'); // false