[Home] > Snippets  > Languages  > JavaScript  > Validation  >  Check if a string is an octal number

Check if a string is an octal number

JavaScript

const isOctal = (str) => /^(0o)?[0-7]+$/i.test(str)

TypeScript

const isOctal = (str: string): boolean => /^(0o)?[0-7]+$/i.test(str)