Created
June 5, 2014 09:27
-
-
Save tsbits/45a336cdf7eee0107e75 to your computer and use it in GitHub Desktop.
Check if a string contains only numbers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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