Files
30-seconds-of-code/snippets/isAlphaNumeric.md
Isabelle Viktoria Maciohsek 268e563e47 Update isAlphaNumeric.md
2020-09-07 12:38:12 +03:00

476 B

title, tags
title tags
isAlphaNumeric string,regexp,beginner

Checks if a string contains only alphanumeric characters.

Use RegExp.prototype.test() to check if input string matches against alphanumeric regex 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