Skip to content

Instantly share code, notes, and snippets.

@masautt
Created September 6, 2019 16:10
Show Gist options
  • Save masautt/9748d1234ef146ae12901a68b4a55c33 to your computer and use it in GitHub Desktop.
Save masautt/9748d1234ef146ae12901a68b4a55c33 to your computer and use it in GitHub Desktop.
How to check if string has only digits in JavaScript?
function checkNum(str) {
return /^\d+$/.test(str)
}
console.log(checkNum("8675309")); // --> true
console.log(checkNum("867S309")); // --> false
// https://stackoverflow.com/questions/1779013/check-if-string-contains-only-digits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment