diff --git a/src/lib/isFloat.js b/src/lib/isFloat.js index 84bdc782c..3d91b8af6 100644 --- a/src/lib/isFloat.js +++ b/src/lib/isFloat.js @@ -9,7 +9,8 @@ export default function isFloat(str, options) { if (str === '' || str === '.' || str === ',' || str === '-' || str === '+') { return false; } - const value = parseFloat(str.replace(',', '.')); + const decimalSeparator = options.locale ? decimal[options.locale] : '.'; + const value = parseFloat(str.replace(decimalSeparator, '.')); return float.test(str) && (!options.hasOwnProperty('min') || isNullOrUndefined(options.min) || value >= options.min) && (!options.hasOwnProperty('max') || isNullOrUndefined(options.max) || value <= options.max) && diff --git a/test/validators.test.js b/test/validators.test.js index a4c3d7193..323d2fe52 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -4857,6 +4857,26 @@ describe('Validators', () => { 'foo', ], }); + test({ + validator: 'isFloat', + args: [{ + locale: 'ar', + min: 3.1, + max: 4, + }], + valid: [ + '3٫1', + '3٫14', + '3٫999', + '4', + ], + invalid: [ + '3٫09', + '4٫01', + '9٫99', + '3', + ], + }); test({ validator: 'isFloat', args: [{