From 7c2983f92e578751346202ea71af8638cf9a3d44 Mon Sep 17 00:00:00 2001 From: rrbharath Date: Sat, 13 Jun 2026 20:37:22 -0400 Subject: [PATCH] Add ja-JP license plate validator --- README.md | 2 +- src/lib/isLicensePlate.js | 7 ++++--- test/validators.test.js | 20 ++++++++++++++++++++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8ef42fd79..9a6ca2dd3 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', 'ja-JP', '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..8d366c7d5 100644 --- a/src/lib/isLicensePlate.js +++ b/src/lib/isLicensePlate.js @@ -10,9 +10,10 @@ const validators = { '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), '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 => - /^[A-Z]{3}[ -]?[0-9][A-Z][0-9]{2}|[A-Z]{3}[ -]?[0-9]{4}$/.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), + 'ja-JP': str => /^[\u3041-\u3096\u4E00-\u9FFF]{1,4}[ -]?\d{2,3}[A-Z]?[ -]?(?![\u304A\u3057\u3078\u3090\u3091\u3093])[\u3042-\u3096][ -]?(\d{1,4}|\d{1,2}-\d{2})$/.test(str), + 'pt-BR': str => + /^[A-Z]{3}[ -]?[0-9][A-Z][0-9]{2}|[A-Z]{3}[ -]?[0-9]{4}$/.test(str), 'pt-PT': str => /^(([A-Z]{2}[ -·]?[0-9]{2}[ -·]?[0-9]{2})|([0-9]{2}[ -·]?[A-Z]{2}[ -·]?[0-9]{2})|([0-9]{2}[ -·]?[0-9]{2}[ -·]?[A-Z]{2})|([A-Z]{2}[ -·]?[0-9]{2}[ -·]?[A-Z]{2}))$/.test(str), 'sq-AL': str => diff --git a/test/validators.test.js b/test/validators.test.js index a4c3d7193..421de3e67 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -15040,6 +15040,26 @@ describe('Validators', () => { 'HU 12-34', ], }); + test({ + validator: 'isLicensePlate', + args: ['ja-JP'], + valid: [ + '\u54C1\u5DDD 300 \u3055 12-34', + '\u8DB3\u7ACB500\u304D21-41', + '\u306A\u306B\u308F 580 \u3042 1234', + '\u5C3E\u5F35\u5C0F\u7267 50A \u308C 1', + ], + invalid: [ + '', + '\u54C1\u5DDD 300 \u3057 12-34', + '\u54C1\u5DDD 3 \u3055 12-34', + 'TOKYO 300 \u3055 12-34', + '\u54C1\u5DDD 300 \u3055 123-4', + '\u54C1\u5DDD 300 \u3055 12345', + '\u54C1\u5DDD_300_\u3055_12-34', + '\u54C1\u5DDD 300 a 12-34', + ], + }); test({ validator: 'isLicensePlate', args: ['any'],