diff --git a/README.md b/README.md index a0ea7a65d..eeaf5d40f 100644 --- a/README.md +++ b/README.md @@ -141,7 +141,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 and equal to any of the integers of the `discreteLengths` array if provided.

`options` is an object which defaults to `{ min: 0, max: undefined, discreteLengths: 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', 'en-SG', 'en-PK', '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-SG', 'en-PK', 'es-AR', 'hu-HU', 'pt-BR', 'pt-PT', 'sq-AL', 'sv-SE', 'fr-FR']` 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 54d80635f..4cc3a6444 100644 --- a/src/lib/isLicensePlate.js +++ b/src/lib/isLicensePlate.js @@ -20,6 +20,7 @@ const validators = { '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()), + 'fr-FR': str => /^([a-zA-Z]{2}[-\s]?\d{3}[-\s]?[a-zA-Z]{2}|[0-9]{1,4}[-\s]?[a-zA-Z]{1,3}[-\s]?[0-9]{2,3})$/i.test(str.trim()), }; export default function isLicensePlate(str, locale) { diff --git a/test/validators.test.js b/test/validators.test.js index 12c5fc2ab..a9af5262e 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -14934,6 +14934,36 @@ describe('Validators', () => { 'GJ054GH4785', ], }); + test({ + validator: 'isLicensePlate', + args: ['fr-FR'], + valid: [ + 'AB-123-CD', + 'ab-123-cd', + 'AB123CD', + 'ab123cd', + 'AB 123 CD', + 'ab 123 cd', + '1234AB12', + '1234ab12', + '1234 ABC 12', + '12 ab 12', + ], + invalid: [ + '', + 'notalicenseplate', + 'ABC-123-CD', + 'AB-1234-CD', + 'AB-123-CDE', + 'AB-123-CCD', + 'AB-1123-CD', + 'AB-123', + 'AABC 123', + 'AB CDE FG', + 'ABC DEF', + '12345 ABCD 34', + ], + }); }); it('should validate VAT numbers', () => { test({