diff --git a/src/lib/isFloat.js b/src/lib/isFloat.js index 84bdc782c..9fe2d602b 100644 --- a/src/lib/isFloat.js +++ b/src/lib/isFloat.js @@ -5,6 +5,9 @@ import { decimal } from './alpha'; export default function isFloat(str, options) { assertString(str); options = options || {}; + if (options.locale && !(options.locale in decimal)) { + throw new Error(`Invalid locale '${options.locale}'`); + } const float = new RegExp(`^(?:[-+])?(?:[0-9]+)?(?:\\${options.locale ? decimal[options.locale] : '.'}[0-9]*)?(?:[eE][\\+\\-]?(?:[0-9]+))?$`); if (str === '' || str === '.' || str === ',' || str === '-' || str === '+') { return false; diff --git a/test/validators.test.js b/test/validators.test.js index 98d2a12ff..60bf0e6ab 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -4940,6 +4940,19 @@ describe('Validators', () => { }); }); + it('should error on invalid locale', () => { + test({ + validator: 'isFloat', + args: [{ locale: 'is-NOT' }], + error: [ + '123', + '123.123', + '123,123', + '3undefined5', + ], + }); + }); + it('should validate hexadecimal strings', () => { test({ validator: 'isHexadecimal',