[Home] >  Validator >  Check if a string contains only letters

Check if a string contains only letters

JavaScript version

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

TypeScript version

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

Examples

isAlpha('helloworld'); // true
isAlpha('HelloWorld'); // true
isAlpha('hello world'); // false
isAlpha('0123456789'); // false