Skip to content

Commit c6f2196

Browse files
profnandaafrederike-ramin
andcommittedFeb 2, 2023
fix(isFloat): fix comma passing as float (#2174)
Co-authored-by: Frederike Ramin <frederike.ramin@digitalservice.bund.de>
1 parent 58f4b13 commit c6f2196

File tree

3 files changed

+3
-2
lines changed

3 files changed

+3
-2
lines changed
 

‎src/lib/isFloat.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default function isFloat(str, options) {
55
assertString(str);
66
options = options || {};
77
const float = new RegExp(`^(?:[-+])?(?:[0-9]+)?(?:\\${options.locale ? decimal[options.locale] : '.'}[0-9]*)?(?:[eE][\\+\\-]?(?:[0-9]+))?$`);
8-
if (str === '' || str === '.' || str === '-' || str === '+') {
8+
if (str === '' || str === '.' || str === ',' || str === '-' || str === '+') {
99
return false;
1010
}
1111
const value = parseFloat(str.replace(',', '.'));

‎src/lib/isPassportNumber.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const passportRegexByCountryCode = {
5252
MY: /^[AHK]\d{8}$/, // MALAYSIA
5353
MX: /^\d{10,11}$/, // MEXICO
5454
NL: /^[A-Z]{2}[A-Z0-9]{6}\d$/, // NETHERLANDS
55-
NZ: /^([Ll]([Aa]|[Dd]|[Ff]|[Hh])|[Ee]([Aa]|[Pp])|[Nn])\d{6}$/, // NEW ZELAND
55+
NZ: /^([Ll]([Aa]|[Dd]|[Ff]|[Hh])|[Ee]([Aa]|[Pp])|[Nn])\d{6}$/, // NEW ZEALAND
5656
PH: /^([A-Z](\d{6}|\d{7}[A-Z]))|([A-Z]{2}(\d{6}|\d{7}))$/, // PHILIPPINES
5757
PK: /^[A-Z]{2}\d{7}$/, // PAKISTAN
5858
PL: /^[A-Z]{2}\d{7}$/, // POLAND

‎test/validators.test.js

+1
Original file line numberDiff line numberDiff line change
@@ -4122,6 +4122,7 @@ describe('Validators', () => {
41224122
' ',
41234123
'',
41244124
'.',
4125+
',',
41254126
'foo',
41264127
'20.foo',
41274128
'2020-01-06T14:31:00.135Z',

0 commit comments

Comments
 (0)