diff --git a/README.md b/README.md index 768f1e48d..941ac91d2 100644 --- a/README.md +++ b/README.md @@ -142,7 +142,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 the string matches the format of a country's license plate.

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

`locale` is one of `['cs-CZ', 'de-DE', 'de-LI', 'en-IN', 'en-PK', 'es-AR', 'hu-HU', '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. **isLuhnNumber(str)** | check if the string passes the [Luhn algorithm check](https://en.wikipedia.org/wiki/Luhn_algorithm). diff --git a/src/lib/isLicensePlate.js b/src/lib/isLicensePlate.js index 48f8ebe99..8476f2f9e 100644 --- a/src/lib/isLicensePlate.js +++ b/src/lib/isLicensePlate.js @@ -18,6 +18,7 @@ const validators = { /^[A-Z]{2}[- ]?((\d{3}[- ]?(([A-Z]{2})|T))|(R[- ]?\d{3}))$/.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()), + 'en-PK': str => /(^[A-Z]{2}((\s|-){0,1})[0-9]{3,4}((\s|-)[0-9]{2}){0,1}$)|(^[A-Z]{3}((\s|-){0,1})[0-9]{3,4}((\s|-)[0-9]{2}){0,1}$)|(^[A-Z]{4}((\s|-){0,1})[0-9]{3,4}((\s|-)[0-9]{2}){0,1}$)|(^[A-Z]((\s|-){0,1})[0-9]{4}((\s|-)[0-9]{2}){0,1}$)/.test(str.trim()), }; export default function isLicensePlate(str, locale) { diff --git a/test/validators.test.js b/test/validators.test.js index a05548335..9bf25a3eb 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -13631,6 +13631,30 @@ describe('Validators', () => { ], invalid: ['mh04ad0045', 'invalidlicenseplate', '4578', '', 'GJ054GH4785'], }); + test({ + validator: 'isLicensePlate', + args: ['en-PK'], + valid: [ + 'P 1789', + 'RL745', + 'RIR 5421', + 'KHI 201', + 'LB6571', + 'LHR-786-23', + 'AJGB 816-10', + 'LES 7891 06', + 'IDS 7871', + 'LEH 4607 15', + ], + invalid: [ + 'ajgb 816-10', + ' 278-37', + 'ABZ-27', + '', + 'ABC-123-', + 'D 272', + ], + }); }); it('should validate VAT numbers', () => { test({