Skip to content

Commit

Permalink
Update patterns and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
typecastcloud committed Jun 26, 2024
1 parent cdefa7f commit e2f13d8
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 58 deletions.
5 changes: 4 additions & 1 deletion src/types/Patterns.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ describe('Input Pattern Tests', () => {
validatePattern('IN', 'VAT_ID', VAT_TEST_DATA)
validatePattern('Worldwide', 'VAT_ID', VAT_TEST_DATA)

// VIES: Covered by VAT ID tests
// VIES only exists in Europe
validatePattern('DE', 'VIES', VIES_TEST_DATA)
validatePattern('FR', 'VIES', VIES_TEST_DATA)
validatePattern('Worldwide', 'VIES', VIES_TEST_DATA)

// Commercial Registration Number
validatePattern('DE', 'COMMERCIAL_REG_NUMBER', CRN_TEST_DATA)
Expand Down
47 changes: 28 additions & 19 deletions src/types/Patterns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,30 @@
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

// Generic Identifier Pattern Definitions
// Reusable Generic Identifier Pattern Definitions
// Pattern definition from https://www.gleif.org/ and ISO 17442
const LEI = /^[A-Za-z0-9]{20}$/ // same for all countries

// Pattern definition from https://taxation-customs.ec.europa.eu/
const EORI = {
EUROPE: /^[A-Z]{2}[A-Za-z0-9]{1,15}$/, // generic pattern for Europe
}

// Pattern definition from https://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl
const VIES = {
EUROPE: /^[A-Z]{2}([A-Za-z0-9](\+|\*|\.)?){2,12}$/, // VIES pattern
}

const VAT_ID = {
Worldwide: /^(?!.*\s$)([A-Za-z0-9-./]\s?){5,15}$/, // generic pattern
VIES: /^[A-Z]{2}[A-Za-z0-9]{1,15}$/, // VIES pattern
Worldwide: /^(?!.*\s$)([A-Za-z0-9](\.|\s|-|\/)?){5,18}$/, // generic pattern
FR: /^(?!.*\s$)([a-zA-Z0-9](-|\s)?){8,15}$/,
DE: /^DE\d{9}$/,
IN: /^[a-zA-Z\d-]{5,6}$/, // TODO: update pattern
IN: /^[a-zA-Z\d-]{5,6}$/,
MX: /^[a-zA-Z\d-&]{12,13}$/,
}
const COMMERCIAL_REG_NUMBER = {
Worldwide: /^(?!.*\s$)([A-Za-z0-9-]\s?){4,21}$/, // generic pattern
DE: /^(?!.*\s$)([A-Za-z0-9-]\s?){9}$/,
Worldwide: /^(?!.*\s$)([A-Za-z0-9](-|\s|\.)?){4,21}$/, // generic pattern
DE: /^(?!.*\s$)([A-Za-z0-9](-|\s)?){9}$/,
FR: /^(?!.*\s$)([A-Za-z0-9]\s?){14,17}$/,
}

Expand All @@ -41,49 +50,49 @@ export const Patterns = {
BPN: /^BPNL[a-z0-9]{12}$/i,
CITY: /^[A-ZÀ-ÿ0-9Śął](([ .'-]|\. )?[A-Za-zÀ-ÿ0-9Śął]{1,40}){1,10}$/,
STREET:
/^([a-zA-Z0-9À-ÿšŚął]{1,40}( ?[.,'/-] ?| )?){1,10}[a-zA-Z0-9À-ÿšŚął.]$/,
/^(?!.*\s$)([a-zA-Z0-9À-ÿšŚął]{1,40}( ?[.,'/-] ?| )?){1,10}[a-zA-Z0-9À-ÿšŚął.]$/,
legalEntityPattern:
/^[a-zA-ZÀ-ÿ\d][a-zA-ZÀ-ÿ\d !#'$@&%()*+,\-_./:;=<>?[\]\\^]{2,50}$/,
/^(?!.*\s$)[a-zA-ZÀ-ÿ\d][a-zA-ZÀ-ÿ\d\s!#'$@&%()*+,\-_./:;=<>?[\]\\^]{2,50}$/,
registeredNamePattern:
/^[a-zA-ZÀ-ÿŚął\d][a-zA-ZÀ-ÿŚął\d !#'$@&%()*+,\-_./:;=<>?[\]\\^]{2,60}$/,
streetHouseNumberPattern: /^[a-zÀ-ÿA-Z\d][a-zA-ZÀ-ÿ\d -]{2,60}$/,
regionPattern: /^(?!.*\s\s)(?!^\s)(?!.*\s$)[a-zA-Z0-9À-ÿŚął,"\s()'-]*$/,
/^(?!.*\s$)[a-zA-ZÀ-ÿŚął\d][a-zA-ZÀ-ÿŚął\d\s!#'$@&%()*+,\-_./:;=<>?[\]\\^]{2,60}$/,
streetHouseNumberPattern: /^(?!.*\s$)[a-zÀ-ÿA-Z\d][a-zA-ZÀ-ÿ\d\s-]{2,60}$/,
regionPattern: /^(?!.*\s$)([a-zA-Z0-9À-ÿŚął,"()'-]\s?)*$/,
postalCodePattern:
/^(?!.*\s\s)(?!^\s)(?!.*\s$)(?=[a-zA-Z\d-]*[-\s]?[a-zA-Z\d-]*$)[a-zA-Z\d\s-]{2,10}$/,
/^(?!.*\s$)(?=[a-zA-Z\d-]*[-\s]?[a-zA-Z\d-]*$)[a-zA-Z\d\s-]{2,10}$/,
countryPattern: /^[A-Za-zÀ-ÿ]{2,3}$/,
IN: {
COMMERCIAL_REG_NUMBER: COMMERCIAL_REG_NUMBER.Worldwide,
VAT_ID: VAT_ID.Worldwide,
LEI_CODE: LEI,
VIES: VAT_ID.VIES,
VIES: VIES.EUROPE,
EORI: EORI.EUROPE,
},
DE: {
COMMERCIAL_REG_NUMBER: COMMERCIAL_REG_NUMBER.Worldwide,
COMMERCIAL_REG_NUMBER: COMMERCIAL_REG_NUMBER.DE,
VAT_ID: VAT_ID.DE,
LEI_CODE: LEI,
VIES: VAT_ID.DE,
VIES: VIES.EUROPE,
EORI: EORI.EUROPE,
},
FR: {
COMMERCIAL_REG_NUMBER: COMMERCIAL_REG_NUMBER.FR,
VAT_ID: VAT_ID.VIES,
VAT_ID: VAT_ID.FR,
LEI_CODE: LEI,
VIES: VAT_ID.VIES,
VIES: VIES.EUROPE,
EORI: EORI.EUROPE,
},
MX: {
COMMERCIAL_REG_NUMBER: COMMERCIAL_REG_NUMBER.Worldwide,
VAT_ID: VAT_ID.MX,
LEI_CODE: LEI,
VIES: VAT_ID.VIES,
VIES: VIES.EUROPE,
EORI: EORI.EUROPE,
},
Worldwide: {
COMMERCIAL_REG_NUMBER: COMMERCIAL_REG_NUMBER.Worldwide,
VAT_ID: VAT_ID.Worldwide,
LEI_CODE: LEI,
VIES: VAT_ID.VIES,
VIES: VIES.EUROPE,
EORI: EORI.EUROPE,
},

Expand Down
3 changes: 2 additions & 1 deletion src/types/testdata/bpn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export const BPN_TEST_DATA = {
invalid: [
' BPNL000000015OHJ', // leading space
'BPNL000000015OHJ ', // trailing space
'',
'', // empty
' ', // whitespace
'word',
'some string',
' BPNL000000000001 ',
Expand Down
2 changes: 2 additions & 0 deletions src/types/testdata/city.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export const CITY_TEST_DATA = {
'Þorlákshöfn',
],
invalid: [
'', // empty
' ', // whitespace
' Munich', // leading whitespace
'Munich ', // trailing whitespace
',',
Expand Down
39 changes: 26 additions & 13 deletions src/types/testdata/crn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,29 @@

export const CRN_TEST_DATA = {
DE: {
valid: [ // Valid records found at https://www.unternehmensregister.de/ureg/ (German Handelsregister)
'HRB 209459',
'HRB 86891',
'HRA 5778',
'HRB 112676',
'HRB 92821',
'VR 9277',
'HRB 42', // Südzucker AG
'HRA 3679 FL'
valid: [
'123456789',
'987654321',
'000000000',
// Valid records found at https://www.unternehmensregister.de/ureg/ (German Handelsregister)
// 'HRB 209459',
// 'HRB 86891',
// 'HRA 5778',
// 'HRB 112676',
// 'HRB 92821',
// 'VR 9277',
// 'HRB 42', // Südzucker AG
// 'HRA 3679 FL'
],
invalid: [
'', // empty
' ', // whitespace
'HRB 209459 ', // trailing whitespace
' HRB 209459', // leading whitespace
'HRB 2094590', // invalid character (double whitespace)
'123456789 ', // trailing whitespace
' 123456789', // leading whitespace
'12345 6789', // invalid character (double whitespace)
// 'HRB 209459 ', // trailing whitespace
// ' HRB 209459', // leading whitespace
// 'HRB 2094590', // invalid character (double whitespace)
],
},
FR: {
Expand All @@ -56,6 +63,8 @@ export const CRN_TEST_DATA = {
'XYZ19991231Z5A',
],
invalid: [
'', // empty
' ', // whitespace
'ABC20010101AAA ', // trailing space
' ABC20010101AAA', // leading space
],
Expand All @@ -66,6 +75,8 @@ export const CRN_TEST_DATA = {
'37AAACP2678Q1ZP',
],
invalid: [
'', // empty
' ', // whitespace
'27AASCS2460H1Z0 ', // trailing space
' 27AASCS2460H1Z0', // leading space
],
Expand All @@ -79,9 +90,11 @@ export const CRN_TEST_DATA = {
'37AAACP2678Q1ZP',
'CHE-123.456.788 TVA', // Swiss TVA ??
'CHE-116.281.710 MWST', // Swiss MWST ??
'CHE-105.909.036' // Swiss UID ??
'CHE-105.909.036', // Swiss UID ??
],
invalid: [
'', // empty
' ', // whitespace
' DE123456789', // leading space
'DE123456789 ', // trailing space
],
Expand Down
4 changes: 4 additions & 0 deletions src/types/testdata/eori.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export const EORI_TEST_DATA = {
"DE987654321098765",
],
invalid: [
'', // empty
' ', // whitespace
'DE123456789012345 ', // trailing whitespace
' DE123456789012345', // leading whitespace
],
Expand All @@ -34,6 +36,8 @@ export const EORI_TEST_DATA = {
"FR987654321098765",
],
invalid: [
'', // empty
' ', // whitespace
'FR123456789012345 ', // trailing space
' FR123456789012345', // leading space
],
Expand Down
10 changes: 10 additions & 0 deletions src/types/testdata/vat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export const VAT_TEST_DATA = {
'DE000000000',
],
invalid: [
'', // empty
' ', // whitespace
'DE1234567890', // too long
'DE12345678', // too short
'DE123456789 ', // trailing space
Expand All @@ -41,6 +43,8 @@ export const VAT_TEST_DATA = {
'FR00000000000',
],
invalid: [
'', // empty
' ', // whitespace
'FR12345678901 ', // trailing space
' FR12345678901', // leading space
],
Expand All @@ -51,6 +55,8 @@ export const VAT_TEST_DATA = {
'P&G851223B24',
],
invalid: [
'', // empty
' ', // whitespace
'AAGB860519G31 ', // trailing space
' AAGB860519G31', // leading space
'AAGB86051', // too short
Expand All @@ -63,6 +69,8 @@ export const VAT_TEST_DATA = {
'37AAACP2678Q1ZP',
],
invalid: [
'', // empty
' ', // whitespace
'27AASCS2460H1Z0 ', // trailing space
' 27AASCS2460H1Z0', // leading space
],
Expand All @@ -77,6 +85,8 @@ export const VAT_TEST_DATA = {
'CHE-116.281.710 MWST', // Swiss with MWST
],
invalid: [
'', // empty
' ', // whitespace
' DE123456789', // leading space
'DE123456789 ', // trailing space
],
Expand Down
29 changes: 5 additions & 24 deletions src/types/testdata/vies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,34 +37,15 @@ export const VIES_TEST_DATA = {
' FRXX999999999', // leading space
],
},
MX: {
valid: [
"AAGB860519G31",
"P&G851223B24",
],
invalid: [
'AAGB860519G31 ', // trailing space
' AAGB860519G31', // leading space
],
},
IN: {
valid: [
"1234567890123Z1",
"22AAAAA0000A1Z5",
],
invalid: [
'22AAAAA0000A1Z5 ', // trailing space
' 22AAAAA0000A1Z5', // leading space
],
},
Worldwide: {
valid: [
"GB123456789012345",
"GB987654321098765",
"DE123456789",
"FRXX999999999",
],
invalid: [
'GB123456789012345 ', // trailing space
' GB123456789012345', // leading space
'DE123456789 ', // trailing space
' DE123456789', // leading space
'DE123 456789', // invalid character (whitespace)
],
},
}

0 comments on commit e2f13d8

Please sign in to comment.