From 4b06c0e2e1ebc0574de8988b365257edfe7e0342 Mon Sep 17 00:00:00 2001 From: Anthony Nandaa Date: Thu, 2 Feb 2023 06:30:22 +0300 Subject: [PATCH] fix(isFloat): fix comma passing as float (#2174) Co-authored-by: Frederike Ramin --- src/lib/isFloat.js | 2 +- test/validators.test.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lib/isFloat.js b/src/lib/isFloat.js index e6cced044..643f9729f 100644 --- a/src/lib/isFloat.js +++ b/src/lib/isFloat.js @@ -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(',', '.')); diff --git a/test/validators.test.js b/test/validators.test.js index 0f1404d59..86b3522b7 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -4122,6 +4122,7 @@ describe('Validators', () => { ' ', '', '.', + ',', 'foo', '20.foo', '2020-01-06T14:31:00.135Z',