From f4d0650dd343dd5e2010c0f014a3bf49b9ed9c0e Mon Sep 17 00:00:00 2001 From: SarthakDudhe Date: Thu, 2 Jul 2026 12:58:24 +0530 Subject: [PATCH] feat: add es-ES license plate validator --- README.md | 2 +- src/lib/isLicensePlate.js | 1 + test/validators.test.js | 20 ++++++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8ef42fd79..3c409ffbe 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', 'es-ES', '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 54d80635f..41f44a4fb 100644 --- a/src/lib/isLicensePlate.js +++ b/src/lib/isLicensePlate.js @@ -9,6 +9,7 @@ const validators = { 'en-IN': str => /^[A-Z]{2}[ -]?[0-9]{1,2}(?:[ -]?[A-Z])(?:[ -]?[A-Z]*)?[ -]?[0-9]{4}$/.test(str), 'en-SG': str => /^[A-Z]{3}[ -]?[\d]{4}[ -]?[A-Z]{1}$/.test(str), 'es-AR': str => /^(([A-Z]{2} ?[0-9]{3} ?[A-Z]{2})|([A-Z]{3} ?[0-9]{3}))$/.test(str), + 'es-ES': str => /^\d{4}[ -]?[BCDFGHJKLMNPRSTVWXYZ]{3}$/.test(str), 'fi-FI': str => /^(?=.{4,7})(([A-Z]{1,3}|[0-9]{1,3})[\s-]?([A-Z]{1,3}|[0-9]{1,5}))$/.test(str), 'hu-HU': str => /^((((?!AAA)(([A-NPRSTVZWXY]{1})([A-PR-Z]{1})([A-HJ-NPR-Z]))|(A[ABC]I)|A[ABC]O|A[A-W]Q|BPI|BPO|UCO|UDO|XAO)-(?!000)\d{3})|(M\d{6})|((CK|DT|CD|HC|H[ABEFIKLMNPRSTVX]|MA|OT|R[A-Z]) \d{2}-\d{2})|(CD \d{3}-\d{3})|(C-(C|X) \d{4})|(X-(A|B|C) \d{4})|(([EPVZ]-\d{5}))|(S A[A-Z]{2} \d{2})|(SP \d{2}-\d{2}))$/.test(str), 'pt-BR': str => diff --git a/test/validators.test.js b/test/validators.test.js index 9c867efae..f87c983b3 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -14771,6 +14771,26 @@ describe('Validators', () => { '12 ABC 34', ], }); + test({ + validator: 'isLicensePlate', + args: ['es-ES'], + valid: [ + '1234 BBB', + '1234BBB', + '0000 ZZZ', + '9876-HJK', + ], + invalid: [ + '', + '123 ABC', + '12345 ABC', + '1234 ABCD', + '1234 AEI', + '1234 QQQ', + '1234 ABC', + 'abcd bbb', + ], + }); test({ validator: 'isLicensePlate', args: ['pt-PT'],