From 8db790f25e88ef8621678c432dd3db330319c675 Mon Sep 17 00:00:00 2001 From: Frederike Ramin Date: Mon, 8 Aug 2022 11:42:07 +0200 Subject: [PATCH] Fix , passing as float --- src/lib/isFloat.js | 2 +- test/validators.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.js b/test/validators.js index 87f73ccd4..039ce70d4 100644 --- a/test/validators.js +++ b/test/validators.js @@ -3947,6 +3947,7 @@ describe('Validators', () => { ' ', '', '.', + ',', 'foo', '20.foo', '2020-01-06T14:31:00.135Z',