Skip to content

Commit

Permalink
fix(isFloat): fix comma passing as float (#2174)
Browse files Browse the repository at this point in the history
Co-authored-by: Frederike Ramin <[email protected]>
  • Loading branch information
profnandaa and frederike-ramin authored Feb 2, 2023
1 parent 58f4b13 commit 4b06c0e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib/isFloat.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default function isFloat(str, options) {
assertString(str);
options = options || {};
const float = new RegExp(`^(?:[-+])?(?:[0-9]+)?(?:\\${options.locale ? decimal[options.locale] : '.'}[0-9]*)?(?:[eE][\\+\\-]?(?:[0-9]+))?$`);
if (str === '' || str === '.' || str === '-' || str === '+') {
if (str === '' || str === '.' || str === ',' || str === '-' || str === '+') {
return false;
}
const value = parseFloat(str.replace(',', '.'));
Expand Down
1 change: 1 addition & 0 deletions test/validators.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4122,6 +4122,7 @@ describe('Validators', () => {
' ',
'',
'.',
',',
'foo',
'20.foo',
'2020-01-06T14:31:00.135Z',
Expand Down

0 comments on commit 4b06c0e

Please sign in to comment.