Created
February 25, 2026 19:10
-
-
Save petergi/710988bc9cb897a138ae13526d32fd34 to your computer and use it in GitHub Desktop.
Checks if a string contains only alphanumeric characters. - Use `RegExp.prototype.test()` to check if the input string matches against the alphanumeric regexp pattern.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Checks if a string contains only alphanumeric characters. | |
| // | |
| // - Use `RegExp.prototype.test()` to check if the input string matches against the alphanumeric regexp pattern. | |
| const isAlphaNumeric = str => /^[a-z0-9]+$/gi.test(str); | |
| isAlphaNumeric('hello123'); // true | |
| isAlphaNumeric('123'); // true | |
| isAlphaNumeric('hello 123'); // false (space character is not alphanumeric) | |
| isAlphaNumeric('#$hello'); // false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment