Skip to content

Instantly share code, notes, and snippets.

@tsbits
Created June 5, 2014 09:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsbits/45a336cdf7eee0107e75 to your computer and use it in GitHub Desktop.
Save tsbits/45a336cdf7eee0107e75 to your computer and use it in GitHub Desktop.
Check if a string contains only numbers
function checkNumber(testedString) {
var newStr = testedString.replace(/(^\s+|\s+$)/g,'');
if (newStr.length > 0) {
if (/[^0-9]/.test(newStr)) return false;
else return true;
} else return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment