diff --git a/src/lib/isFloat.js b/src/lib/isFloat.js index 84bdc782c..544fae806 100644 --- a/src/lib/isFloat.js +++ b/src/lib/isFloat.js @@ -6,7 +6,10 @@ 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 === '-' || str === '+') { + const decimalSep = options.locale ? decimal[options.locale] : '.'; + if (str === '' || str === '.' || str === ',' || str === '-' || str === '+' + || str === '+.' || str === '-.' || str === '+,' || str === '-,' + || str === `+${decimalSep}` || str === `-${decimalSep}`) { return false; } const value = parseFloat(str.replace(',', '.')); diff --git a/test/validators.test.js b/test/validators.test.js index 7d9d12690..8f361c18b 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -4657,6 +4657,8 @@ describe('Validators', () => { 'foo', '20.foo', '2020-01-06T14:31:00.135Z', + '+.', + '-.', ], }); @@ -4711,6 +4713,8 @@ describe('Validators', () => { '', '.', 'foo', + '+,', + '-,', ], }); @@ -4738,6 +4742,8 @@ describe('Validators', () => { '', '.', 'foo', + '+٫', + '-٫', ], });