Skip to content

Instantly share code, notes, and snippets.

@thenriquedb
Created June 27, 2020 20:25
Show Gist options
  • Save thenriquedb/6a9fcf87826d4e708395bce6ecb99d96 to your computer and use it in GitHub Desktop.
Save thenriquedb/6a9fcf87826d4e708395bce6ecb99d96 to your computer and use it in GitHub Desktop.
validate input float in javascript
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