diff --git a/README.md b/README.md index 0d2ed2bce..a8993c61b 100644 --- a/README.md +++ b/README.md @@ -139,7 +139,7 @@ Validator | Description **isJWT(str)** | check if the string is valid JWT token. **isLatLong(str [, options])** | check if the string is a valid latitude-longitude coordinate in the format `lat,long` or `lat, long`.

`options` is an object that defaults to `{ checkDMS: false }`. Pass `checkDMS` as `true` to validate DMS(degrees, minutes, and seconds) latitude-longitude format. **isLength(str [, options])** | check if the string's length falls in a range.

`options` is an object which defaults to `{min:0, max: undefined}`. Note: this function takes into account surrogate pairs. -**isLicensePlate(str [, locale])** | check if string matches the format of a country's license plate.

(locale is one of `['cs-CZ', 'de-DE', 'de-LI', 'fi-FI', pt-PT', 'sq-AL', 'pt-BR']` or `any`) +**isLicensePlate(str [, locale])** | check if string matches the format of a country's license plate.

(locale is one of `['cs-CZ', 'de-DE', 'de-LI', 'fi-FI', 'pt-BR', 'pt-PT', 'sq-AL', 'sv-SE']` or `any`) **isLocale(str)** | check if the string is a locale **isLowercase(str)** | check if the string is lowercase. **isMACAddress(str [, options])** | check if the string is a MAC address.

`options` is an object which defaults to `{no_separators: false}`. If `no_separators` is true, the validator will allow MAC addresses without separators. Also, it allows the use of hyphens, spaces or dots e.g '01 02 03 04 05 ab', '01-02-03-04-05-ab' or '0102.0304.05ab'. The options also allow a `eui` property to specify if it needs to be validated against EUI-48 or EUI-64. The accepted values of `eui` are: 48, 64. diff --git a/src/lib/isLicensePlate.js b/src/lib/isLicensePlate.js index d6b27a5ad..668064f13 100644 --- a/src/lib/isLicensePlate.js +++ b/src/lib/isLicensePlate.js @@ -13,6 +13,8 @@ const validators = { /^[A-Z]{2}[- ]?((\d{3}[- ]?(([A-Z]{2})|T))|(R[- ]?\d{3}))$/.test(str), 'pt-BR': str => /^[A-Z]{3}[ -]?[0-9][A-Z][0-9]{2}|[A-Z]{3}[ -]?[0-9]{4}$/.test(str), + 'sv-SE': str => + /^[A-HJ-PR-UW-Z]{3} ?[\d]{2}[A-HJ-PR-UW-Z1-9]$|(^[A-ZÅÄÖ ]{2,7}$)/.test(str.trim()), }; export default function isLicensePlate(str, locale) { diff --git a/test/validators.js b/test/validators.js index 76ec3d95a..be8a4df60 100644 --- a/test/validators.js +++ b/test/validators.js @@ -11767,6 +11767,44 @@ describe('Validators', () => { 'FS AB 1234 A', ], }); + test({ + validator: 'isLicensePlate', + args: ['sv-SE'], + valid: [ + 'ABC 123', + 'ABC 12A', + 'ABC123', + 'ABC12A', + 'A WORD', + 'WORD', + 'ÅSNA', + 'EN VARG', + 'CERISE', + 'AA', + 'ABCDEFG', + 'ÅÄÖ', + 'ÅÄÖ ÅÄÖ', + ], + invalid: [ + '', + ' ', + 'IQV 123', + 'IQV123', + 'ABI 12Q', + 'ÅÄÖ 123', + 'ÅÄÖ 12A', + 'AB1 A23', + 'AB1 12A', + 'lower', + 'abc 123', + 'abc 12A', + 'abc 12a', + 'AbC 12a', + 'WORDLONGERTHANSEVENCHARACTERS', + 'A', + 'ABC-123', + ], + }); }); it('should validate VAT numbers', () => { test({