From 54e5ff561c687c1c9c482c6d94df99afbfe7fe4d Mon Sep 17 00:00:00 2001 From: phxgg Date: Fri, 17 Oct 2025 14:15:23 +0300 Subject: [PATCH 1/3] feat: add greek license plate validation --- README.md | 2 +- src/lib/isLicensePlate.js | 1 + test/validators.test.js | 21 +++++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a0ea7a65d..b54aeaa00 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', 'el-GR']` 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..d78a155d6 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()), + 'el-GR': str => /^[ABEZHIKMNOPTYX]{3}[- ]?\d{4}$/.test(str.trim()), }; export default function isLicensePlate(str, locale) { diff --git a/test/validators.test.js b/test/validators.test.js index 12c5fc2ab..024e6a733 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -14549,6 +14549,27 @@ describe('Validators', () => { }); }); it('should be valid license plate', () => { + test({ + validator: 'isLicensePlate', + args: ['el-GR'], + valid: [ + 'ABE1234', + 'ABE 1234', + 'ABE-1234', + ], + invalid: [ + '', + 'notalicenseplate', + 'AB 1234', + 'A 1234', + 'ABCD 1234', + 'ABE123', + 'ABE 123', + 'ABE-123', + 'ABC 1234', + 'ABC-1234', + ], + }); test({ validator: 'isLicensePlate', args: ['es-AR'], From de11c5a48d869d475e1989aff1cdcb5f4d1822e2 Mon Sep 17 00:00:00 2001 From: phxgg Date: Fri, 17 Oct 2025 14:27:37 +0300 Subject: [PATCH 2/3] feat: accept older legacy plates that used two letters and four digits --- src/lib/isLicensePlate.js | 2 +- test/validators.test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/isLicensePlate.js b/src/lib/isLicensePlate.js index d78a155d6..40c2b5de9 100644 --- a/src/lib/isLicensePlate.js +++ b/src/lib/isLicensePlate.js @@ -20,7 +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()), - 'el-GR': str => /^[ABEZHIKMNOPTYX]{3}[- ]?\d{4}$/.test(str.trim()), + 'el-GR': str => /^[ABEZHIKMNOPTYX]{2,3}[- ]?\d{4}$/.test(str.trim()), }; export default function isLicensePlate(str, locale) { diff --git a/test/validators.test.js b/test/validators.test.js index 024e6a733..8b6d74365 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -14556,11 +14556,11 @@ describe('Validators', () => { 'ABE1234', 'ABE 1234', 'ABE-1234', + 'AB 1234', ], invalid: [ '', 'notalicenseplate', - 'AB 1234', 'A 1234', 'ABCD 1234', 'ABE123', From ec14ae2e4daed50fed4d3ddaaf71f57904215995 Mon Sep 17 00:00:00 2001 From: phxgg Date: Fri, 17 Oct 2025 14:32:14 +0300 Subject: [PATCH 3/3] feat: add more tests --- test/validators.test.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/validators.test.js b/test/validators.test.js index 8b6d74365..31a54300c 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -14556,7 +14556,11 @@ describe('Validators', () => { 'ABE1234', 'ABE 1234', 'ABE-1234', + 'POI 0001', + 'KZT-7890', + 'XYZ5678', 'AB 1234', + 'TY0101', ], invalid: [ '',