Last active
February 27, 2018 17:05
-
-
Save danakt/5e48122cbffb9e1e077fcc8fbebe3493 to your computer and use it in GitHub Desktop.
Validate text input for numer
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
/** | |
* Checks text input for valid integer/float | |
* @param {string} value The input value | |
* @returns {boolean} Result of the validate | |
* | |
* @example | |
* validateInputForNumber('123') // true | |
* validateInputForNumber('123.123') // true | |
* validateInputForNumber('123.') // (!) still true | |
* | |
* validateInputForNumber('123.123.123') // false | |
* validateInputForNumber('g12redfso5tre45llm') // false | |
*/ | |
export function validateInputForNumber(value) { | |
return /^([0-9]+\.?([0-9]+)?)$/.test(value) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment