Skip to content

Commit

Permalink
fix(isFloat): fix comma passing as float (#2174)
Browse files Browse the repository at this point in the history
Co-authored-by: Frederike Ramin <[email protected]>
  • Loading branch information
profnandaa and frederike-ramin committed Feb 2, 2023
1 parent 58f4b13 commit c6f2196
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/lib/isFloat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(',', '.'));
Expand Down
2 changes: 1 addition & 1 deletion src/lib/isPassportNumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const passportRegexByCountryCode = {
MY: /^[AHK]\d{8}$/, // MALAYSIA
MX: /^\d{10,11}$/, // MEXICO
NL: /^[A-Z]{2}[A-Z0-9]{6}\d$/, // NETHERLANDS
NZ: /^([Ll]([Aa]|[Dd]|[Ff]|[Hh])|[Ee]([Aa]|[Pp])|[Nn])\d{6}$/, // NEW ZELAND
NZ: /^([Ll]([Aa]|[Dd]|[Ff]|[Hh])|[Ee]([Aa]|[Pp])|[Nn])\d{6}$/, // NEW ZEALAND
PH: /^([A-Z](\d{6}|\d{7}[A-Z]))|([A-Z]{2}(\d{6}|\d{7}))$/, // PHILIPPINES
PK: /^[A-Z]{2}\d{7}$/, // PAKISTAN
PL: /^[A-Z]{2}\d{7}$/, // POLAND
Expand Down
1 change: 1 addition & 0 deletions test/validators.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4122,6 +4122,7 @@ describe('Validators', () => {
' ',
'',
'.',
',',
'foo',
'20.foo',
'2020-01-06T14:31:00.135Z',
Expand Down

0 comments on commit c6f2196

Please sign in to comment.