Created
June 27, 2020 20:25
-
-
Save thenriquedb/6a9fcf87826d4e708395bce6ecb99d96 to your computer and use it in GitHub Desktop.
validate input float in javascript
This file contains hidden or 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
const validate = (value) => { | |
if (!parseFloat(value)) { | |
setQuantity(''); | |
setSubTotal(0); | |
return; | |
} | |
const valueStr = value.toString().replace(',', '.'); | |
if ((valueStr.match(/\./gi) || []).length > 1) return; | |
return valueStr; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment