Skip to content

Commit 60b6cf0

Browse files
zeno4evertheteladras
authored andcommitted
feat(isVAT): add dutch NL locale (validatorjs#1825)
for hacktober validatorjs#1742 if you want to extend it more check : https://www.oreilly.com/library/view/regular-expressions-cookbook/9781449327453/ch04s21.html
1 parent c3f0187 commit 60b6cf0

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ Validator | Description
165165
**isURL(str [, options])** | check if the string is an URL.<br/><br/>`options` is an object which defaults to `{ protocols: ['http','https','ftp'], require_tld: true, require_protocol: false, require_host: true, require_port: false, require_valid_protocol: true, allow_underscores: false, host_whitelist: false, host_blacklist: false, allow_trailing_dot: false, allow_protocol_relative_urls: false, allow_fragments: true, allow_query_components: true, disallow_auth: false, validate_length: true }`.<br/><br/>require_protocol - if set as true isURL will return false if protocol is not present in the URL.<br/>require_valid_protocol - isURL will check if the URL's protocol is present in the protocols option.<br/>protocols - valid protocols can be modified with this option.<br/>require_host - if set as false isURL will not check if host is present in the URL.<br/>require_port - if set as true isURL will check if port is present in the URL.<br/>allow_protocol_relative_urls - if set as true protocol relative URLs will be allowed.<br/>allow_fragments - if set as false isURL will return false if fragments are present.<br/>allow_query_components - if set as false isURL will return false if query components are present.<br/>validate_length - if set as false isURL will skip string length validation (2083 characters is IE max URL length).
166166
**isUUID(str [, version])** | check if the string is a UUID (version 1, 2, 3, 4 or 5).
167167
**isVariableWidth(str)** | check if the string contains a mixture of full and half-width chars.
168-
**isVAT(str, countryCode)** | checks that the string is a [valid VAT number](https://en.wikipedia.org/wiki/VAT_identification_number) if validation is available for the given country code matching [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2). <br/><br/>Available country codes: `[ 'GB', 'IT' ]`.
168+
**isVAT(str, countryCode)** | checks that the string is a [valid VAT number](https://en.wikipedia.org/wiki/VAT_identification_number) if validation is available for the given country code matching [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2). <br/><br/>Available country codes: `[ 'GB', 'IT','NL' ]`.
169169
**isWhitelisted(str, chars)** | checks characters if they appear in the whitelist.
170170
**matches(str, pattern [, modifiers])** | check if string matches the pattern.<br/><br/>Either `matches('foo', /foo/i)` or `matches('foo', 'foo', 'i')`.
171171

src/lib/isVAT.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import assertString from './util/assertString';
33
export const vatMatchers = {
44
GB: /^GB((\d{3} \d{4} ([0-8][0-9]|9[0-6]))|(\d{9} \d{3})|(((GD[0-4])|(HA[5-9]))[0-9]{2}))$/,
55
IT: /^(IT)?[0-9]{11}$/,
6+
NL: /^(NL)?[0-9]{9}B[0-9]{2}$/,
67
};
78

89
export default function isVAT(str, countryCode) {

test/validators.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11351,7 +11351,7 @@ describe('Validators', () => {
1135111351
],
1135211352
});
1135311353
});
11354-
it('should validate english VAT numbers', () => {
11354+
it('should validate VAT numbers', () => {
1135511355
test({
1135611356
validator: 'isVAT',
1135711357
args: ['GB'],
@@ -11381,7 +11381,6 @@ describe('Validators', () => {
1138111381
'GBHA499',
1138211382
],
1138311383
});
11384-
1138511384
test({
1138611385
validator: 'isVAT',
1138711386
args: ['IT'],
@@ -11397,7 +11396,21 @@ describe('Validators', () => {
1139711396
'IT123456789',
1139811397
],
1139911398
});
11400-
11399+
test({
11400+
validator: 'isVAT',
11401+
args: ['NL'],
11402+
valid: [
11403+
'NL123456789B10',
11404+
'123456789B10',
11405+
],
11406+
invalid: [
11407+
'NL12345678 910',
11408+
'NL 123456789101',
11409+
'NL123456789B1',
11410+
'GB12345678910',
11411+
'NL123456789',
11412+
],
11413+
});
1140111414
test({
1140211415
validator: 'isVAT',
1140311416
args: ['invalidCountryCode'],

0 commit comments

Comments
 (0)