Skip to content

Commit 76403fe

Browse files
conflicts
1 parent 10f5659 commit 76403fe

File tree

4 files changed

+144
-4
lines changed

4 files changed

+144
-4
lines changed

SECURITY.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Security Policy
2+
3+
## Supported Versions
4+
5+
In the case of a confirmed security issue, only the current version of validator is guaranteed to be patched.
6+
7+
## Reporting a Vulnerability
8+
9+
**Please don't disclose security-related issues publicly.**
10+
11+
If you discover a vulnerability within validator, please use [huntr.dev disclosure form](https://huntr.dev/bounties/disclose/?target=https://github.com/validatorjs/validator.js). We will try to validate and respond to reports in a reasonable time. if the issue is confirmed, we will create a security advisory and a patch as soon as possible.

src/lib/isLicensePlate.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ const validators = {
1414
/^[A-Z]{2}[- ]?((\d{3}[- ]?(([A-Z]{2})|T))|(R[- ]?\d{3}))$/.test(str),
1515
'pt-BR': str =>
1616
/^[A-Z]{3}[ -]?[0-9][A-Z][0-9]{2}|[A-Z]{3}[ -]?[0-9]{4}$/.test(str),
17+
'sv-SE': str =>
18+
/^[A-HJ-PR-UW-Z]{3} ?[\d]{2}[A-HJ-PR-UW-Z1-9]$|(^[A-ZÅÄÖ ]{2,7}$)/.test(str.trim()),
1719
};
1820

1921
export default function isLicensePlate(str, locale) {

src/lib/isTaxID.js

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,36 @@ function bgBgCheck(tin) {
6060
return checksum === digits[9];
6161
}
6262

63+
/**
64+
* Check if an input is a valid Canadian SIN (Social Insurance Number)
65+
*
66+
* The Social Insurance Number (SIN) is a 9 digit number that
67+
* you need to work in Canada or to have access to government programs and benefits.
68+
*
69+
* https://en.wikipedia.org/wiki/Social_Insurance_Number
70+
* https://www.canada.ca/en/employment-social-development/services/sin.html
71+
* https://www.codercrunch.com/challenge/819302488/sin-validator
72+
*
73+
* @param {string} input
74+
* @return {boolean}
75+
*/
76+
function isCanadianSIN(input) {
77+
const digitsArray = input.split('');
78+
const even = digitsArray
79+
.filter((_, idx) => idx % 2)
80+
.map(i => Number(i) * 2)
81+
.join('')
82+
.split('');
83+
84+
const total = digitsArray
85+
.filter((_, idx) => !(idx % 2))
86+
.concat(even)
87+
.map(i => Number(i))
88+
.reduce((acc, cur) => acc + cur);
89+
90+
return (total % 10 === 0);
91+
}
92+
6393
/*
6494
* cs-CZ validation function
6595
* (Rodné číslo (RČ), persons only)
@@ -1096,14 +1126,14 @@ function svSeCheck(tin) {
10961126
* uppercase and lowercase letters are acceptable.
10971127
*/
10981128
const taxIdFormat = {
1099-
11001129
'bg-BG': /^\d{10}$/,
11011130
'cs-CZ': /^\d{6}\/{0,1}\d{3,4}$/,
11021131
'de-AT': /^\d{9}$/,
11031132
'de-DE': /^[1-9]\d{10}$/,
11041133
'dk-DK': /^\d{6}-{0,1}\d{4}$/,
11051134
'el-CY': /^[09]\d{7}[A-Z]$/,
11061135
'el-GR': /^([0-4]|[7-9])\d{8}$/,
1136+
'en-CA': /^\d{9}$/,
11071137
'en-GB': /^\d{10}$|^(?!GB|NK|TN|ZZ)(?![DFIQUV])[A-Z](?![DFIQUVO])[A-Z]\d{6}[ABCD ]$/i,
11081138
'en-IE': /^\d{7}[A-W][A-IW]{0,1}$/i,
11091139
'en-US': /^\d{2}[- ]{0,1}\d{7}$/,
@@ -1126,23 +1156,23 @@ const taxIdFormat = {
11261156
'sk-SK': /^\d{6}\/{0,1}\d{3,4}$/,
11271157
'sl-SI': /^[1-9]\d{7}$/,
11281158
'sv-SE': /^(\d{6}[-+]{0,1}\d{4}|(18|19|20)\d{6}[-+]{0,1}\d{4})$/,
1129-
11301159
};
11311160
// taxIdFormat locale aliases
11321161
taxIdFormat['lb-LU'] = taxIdFormat['fr-LU'];
11331162
taxIdFormat['lt-LT'] = taxIdFormat['et-EE'];
11341163
taxIdFormat['nl-BE'] = taxIdFormat['fr-BE'];
1164+
taxIdFormat['fr-CA'] = taxIdFormat['en-CA'];
11351165

11361166
// Algorithmic tax id check functions for various locales
11371167
const taxIdCheck = {
1138-
11391168
'bg-BG': bgBgCheck,
11401169
'cs-CZ': csCzCheck,
11411170
'de-AT': deAtCheck,
11421171
'de-DE': deDeCheck,
11431172
'dk-DK': dkDkCheck,
11441173
'el-CY': elCyCheck,
11451174
'el-GR': elGrCheck,
1175+
'en-CA': isCanadianSIN,
11461176
'en-IE': enIeCheck,
11471177
'en-US': enUsCheck,
11481178
'es-ES': esEsCheck,
@@ -1164,12 +1194,12 @@ const taxIdCheck = {
11641194
'sk-SK': skSkCheck,
11651195
'sl-SI': slSiCheck,
11661196
'sv-SE': svSeCheck,
1167-
11681197
};
11691198
// taxIdCheck locale aliases
11701199
taxIdCheck['lb-LU'] = taxIdCheck['fr-LU'];
11711200
taxIdCheck['lt-LT'] = taxIdCheck['et-EE'];
11721201
taxIdCheck['nl-BE'] = taxIdCheck['fr-BE'];
1202+
taxIdCheck['fr-CA'] = taxIdCheck['en-CA'];
11731203

11741204
// Regexes for locales where characters should be omitted before checking format
11751205
const allsymbols = /[-\\\/!@#$%\^&\*\(\)\+\=\[\]]+/g;

test/validators.js

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10312,6 +10312,23 @@ describe('Validators', () => {
1031210312
'A1A 1A1',
1031310313
'X0A-0H0',
1031410314
'V5K 0A1',
10315+
'A1C 3S4',
10316+
'A1C3S4',
10317+
'a1c 3s4',
10318+
'V9A 7N2',
10319+
'B3K 5X5',
10320+
'K8N 5W6',
10321+
'K1A 0B1',
10322+
'B1Z 0B9',
10323+
],
10324+
invalid: [
10325+
' ',
10326+
'invalid value',
10327+
'a1a1a',
10328+
'A1A 1A1',
10329+
'K1A 0D1',
10330+
'W1A 0B1',
10331+
'Z1A 0B1',
1031510332
],
1031610333
},
1031710334
{
@@ -10517,6 +10534,8 @@ describe('Validators', () => {
1051710534
'78-399',
1051810535
'39-490',
1051910536
'38-483',
10537+
'05-800',
10538+
'54-060',
1052010539
],
1052110540
},
1052210541
{
@@ -10575,6 +10594,9 @@ describe('Validators', () => {
1057510594
'65000',
1057610595
'65080',
1057710596
'01000',
10597+
'51901',
10598+
'51909',
10599+
'49125',
1057810600
],
1057910601
},
1058010602
{
@@ -10950,6 +10972,43 @@ describe('Validators', () => {
1095010972
'658426713',
1095110973
'558426713'],
1095210974
});
10975+
test({
10976+
validator: 'isTaxID',
10977+
args: ['en-CA'],
10978+
valid: [
10979+
'000000000',
10980+
'521719666',
10981+
'469317481',
10982+
'120217450',
10983+
'480534858',
10984+
'325268597',
10985+
'336475660',
10986+
'744797853',
10987+
'130692544',
10988+
'046454286',
10989+
],
10990+
invalid: [
10991+
' ',
10992+
'any value',
10993+
'012345678',
10994+
'111111111',
10995+
'999999999',
10996+
'657449110',
10997+
'74 47 978 53',
10998+
'744 797 853',
10999+
'744-797-853',
11000+
'981062432',
11001+
'267500713',
11002+
'2675o0713',
11003+
'70597312',
11004+
'7058973122',
11005+
'069437151',
11006+
'046454281',
11007+
'146452286',
11008+
'30x92544',
11009+
'30692544',
11010+
],
11011+
});
1095311012
test({
1095411013
validator: 'isTaxID',
1095511014
args: ['en-GB'],
@@ -11837,6 +11896,44 @@ describe('Validators', () => {
1183711896
'FS AB 1234 A',
1183811897
],
1183911898
});
11899+
test({
11900+
validator: 'isLicensePlate',
11901+
args: ['sv-SE'],
11902+
valid: [
11903+
'ABC 123',
11904+
'ABC 12A',
11905+
'ABC123',
11906+
'ABC12A',
11907+
'A WORD',
11908+
'WORD',
11909+
'ÅSNA',
11910+
'EN VARG',
11911+
'CERISE',
11912+
'AA',
11913+
'ABCDEFG',
11914+
'ÅÄÖ',
11915+
'ÅÄÖ ÅÄÖ',
11916+
],
11917+
invalid: [
11918+
'',
11919+
' ',
11920+
'IQV 123',
11921+
'IQV123',
11922+
'ABI 12Q',
11923+
'ÅÄÖ 123',
11924+
'ÅÄÖ 12A',
11925+
'AB1 A23',
11926+
'AB1 12A',
11927+
'lower',
11928+
'abc 123',
11929+
'abc 12A',
11930+
'abc 12a',
11931+
'AbC 12a',
11932+
'WORDLONGERTHANSEVENCHARACTERS',
11933+
'A',
11934+
'ABC-123',
11935+
],
11936+
});
1184011937
});
1184111938
it('should validate VAT numbers', () => {
1184211939
test({

0 commit comments

Comments
 (0)