Skip to content

Commit

Permalink
fix(isMobillePhone): update nl_NL locale (#1311)
Browse files Browse the repository at this point in the history
* nl_NL formatting update

6 is not optional: 
  correct: 0612345678, incorrect: 012345678
  - change: '6?' to '6{1}'

countryCode ('+31'), may also contain '00' instead of '+'
  correct, either: '+31612345678' || '0031612345678'
  - change: '(\+)' to '(\+|00)'

when specifying country code it's optional to provide '0' between braces before 6 (eg: '+31(0)6...')
  correct, either: '+31(0)612345678' || +31612345678
- change: ^(((\+|00)?31\(0\))|((\+|00)?31)|0)6{1}\d{8}$

* fix nl_NL mobile phone

same as previous commit

* updated test for new nl_NL mobile format

* replace ; with , to succeed tests

* updating (in)valid testdata to include previous data
  • Loading branch information
Erik authored May 29, 2020
1 parent 3dfad25 commit 1e4011a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/isMobilePhone.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ var phones = {
'nb-NO': /^(\+?47)?[49]\d{7}$/,
'ne-NP': /^(\+?977)?9[78]\d{8}$/,
'nl-BE': /^(\+?32|0)4?\d{8}$/,
'nl-NL': /^(\+?31|0)6?\d{8}$/,
'nl-NL': /^(((\+|00)?31\(0\))|((\+|00)?31)|0)6{1}\d{8}$/,
'nn-NO': /^(\+?47)?[49]\d{7}$/,
'pl-PL': /^(\+?48)? ?[5-8]\d ?\d{3} ?\d{2} ?\d{2}$/,
'pt-BR': /(?=^(\+?5{2}\-?|0)[1-9]{2}\-?\d{4}\-?\d{4}$)(^(\+?5{2}\-?|0)[1-9]{2}\-?[6-9]{1}\d{3}\-?\d{4}$)|(^(\+?5{2}\-?|0)[1-9]{2}\-?9[6-9]{1}\d{3}\-?\d{4}$)/,
Expand Down Expand Up @@ -151,4 +151,4 @@ function isMobilePhone(str, locale, options) {
}

var locales = Object.keys(phones);
exports.locales = locales;
exports.locales = locales;
2 changes: 1 addition & 1 deletion src/lib/isMobilePhone.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const phones = {
'nb-NO': /^(\+?47)?[49]\d{7}$/,
'ne-NP': /^(\+?977)?9[78]\d{8}$/,
'nl-BE': /^(\+?32|0)4?\d{8}$/,
'nl-NL': /^(\+?31|0)6?\d{8}$/,
'nl-NL': /^(((\+|00)?31\(0\))|((\+|00)?31)|0)6{1}\d{8}$/,
'nn-NO': /^(\+?47)?[49]\d{7}$/,
'pl-PL': /^(\+?48)? ?[5-8]\d ?\d{3} ?\d{2} ?\d{2}$/,
'pt-BR': /(?=^(\+?5{2}\-?|0)[1-9]{2}\-?\d{4}\-?\d{4}$)(^(\+?5{2}\-?|0)[1-9]{2}\-?[6-9]{1}\d{3}\-?\d{4}$)|(^(\+?5{2}\-?|0)[1-9]{2}\-?9[6-9]{1}\d{3}\-?\d{4}$)/,
Expand Down
15 changes: 11 additions & 4 deletions test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -6156,20 +6156,27 @@ describe('Validators', () => {
locale: 'nl-NL',
valid: [
'0670123456',
'+31670123456',
'0612345678',
'31612345678',
'31670123456',
'021234567',
'+3121234567',
'3121234567',
'+31612345678',
'+31670123456',
'+31(0)612345678',
'0031612345678',
'0031(0)612345678',
],
invalid: [
'12345',
'+3112345',
'3112345',
'06701234567',
'012345678',
'+3104701234567',
'3104701234567',
'0212345678',
'021234567',
'+3121234567',
'3121234567',
'+310212345678',
'310212345678',
],
Expand Down

0 comments on commit 1e4011a

Please sign in to comment.