Skip to main content

Check if a string contains only ASCII characters

JavaScript version

const isAscii = (str) => /^[\x00-\x7F]+$/.test(str);

TypeScript version

const isAscii = (str: string): boolean => /^[\x00-\x7F]+$/.test(str);

Comments