GitHub 6219★

Check if a string contains only letters and numbers

JavaScript version

const isAlphanumeric = (str) => /^[0-9A-Z]+$/i.test(str);

TypeScript version

const isAlphanumeric = (str: string): boolean => /^[0-9A-Z]+$/i.test(str);

Examples

isAlphanumeric('helloworld'); // true
isAlphanumeric('HelloWorld'); // true
isAlphanumeric('hello world'); // false
isAlphanumeric('hello123'); // true
isAlphanumeric('hello 123'); // false
Follow me on and to get more useful contents.