Repository: validatorjs/validator.js
Pull request #1944 (2022-03-22 17:10:57)

feat(isLicensePlate): added License Plate Regex for en-IN and all Indian locale
Added support for Indian license plate validation. Valid examples from [Wikipedia](https://en.wikipedia.org/wiki/Vehicle_registration_plates_of_India):

MH 04 AZ 4562

MH : STATE_CODE 
04 :  DISTRICT_CODE
AZ : UNIQUE_LETTERS 
4562 : UNIQUE_NUMBERING

Basically all options can be written with dash, with space or all together or without symbol.


Patch:
diff --git a/README.md b/README.md
index b2b6416..16a1ee8 100644
--- a/README.md
+++ b/README.md
@@ -140,7 +140,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`.<br/><br/>`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.<br/><br/>`options` is an object which defaults to `{min:0, max: undefined}`. Note: this function takes into account surrogate pairs.
-**isLicensePlate(str [, locale])**     | check if string matches the format of a country's license plate.<br/><br/>(locale is one of `['cs-CZ', 'de-DE', 'de-LI', 'fi-FI', 'pt-BR', 'pt-PT', 'sq-AL', 'sv-SE']` or `any`)
+**isLicensePlate(str [, locale])**     | check if string matches the format of a country's license plate.<br/><br/>(locale is one of `['cs-CZ', 'de-DE', 'de-LI', 'fi-FI', 'pt-BR', 'pt-PT', 'sq-AL', 'sv-SE', 'en-IN', 'hi-IN', 'gu-IN', 'as-IN', 'bn-IN', 'kn-IN', 'ml-IN', 'mr-IN', 'or-IN', 'pa-IN', 'sa-IN', 'ta-IN', 'te-IN', 'kok-IN']` or `any`)
 **isLocale(str)**                       | check if the string is a locale
 **isLowercase(str)**                    | check if the string is lowercase.
 **isMACAddress(str [, options])**                   | check if the string is a MAC address.<br/><br/>`options` is an object which defaults to `{no_separators: false}`. If `no_separators` is true, the validator will allow MAC addresses without separators. Also, it allows the use of hyphens, spaces or dots e.g  '01 02 03 04 05 ab', '01-02-03-04-05-ab' or '0102.0304.05ab'. The options also allow a `eui` property to specify if it needs to be validated against EUI-48 or EUI-64. The accepted values of `eui` are: 48, 64.
diff --git a/src/lib/isLicensePlate.js b/src/lib/isLicensePlate.js
index 668064f..d65917e 100644
--- a/src/lib/isLicensePlate.js
+++ b/src/lib/isLicensePlate.js
@@ -15,8 +15,23 @@ const validators = {
     /^[A-Z]{3}[ -]?[0-9][A-Z][0-9]{2}|[A-Z]{3}[ -]?[0-9]{4}$/.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-IN': str => /^[A-Z]{2}[ -]?[0-9]{1,2}(?:[ -]?[A-Z])(?:[ -]?[A-Z]*)?[ -]?[0-9]{4}$/.test(str),
 };
 
+validators['hi-IN'] = validators['en-IN'];
+validators['gu-IN'] = validators['en-IN'];
+validators['as-IN'] = validators['en-IN'];
+validators['bn-IN'] = validators['en-IN'];
+validators['kn-IN'] = validators['en-IN'];
+validators['ml-IN'] = validators['en-IN'];
+validators['mr-IN'] = validators['en-IN'];
+validators['or-IN'] = validators['en-IN'];
+validators['pa-IN'] = validators['en-IN'];
+validators['sa-IN'] = validators['en-IN'];
+validators['ta-IN'] = validators['en-IN'];
+validators['te-IN'] = validators['en-IN'];
+validators['kok-IN'] = validators['en-IN'];
+
 export default function isLicensePlate(str, locale) {
   assertString(str);
   if (locale in validators) {


Test patch:
diff --git a/test/validators.js b/test/validators.js
index 61ffe09..17a1d48 100644
--- a/test/validators.js
+++ b/test/validators.js
@@ -11864,6 +11864,20 @@ describe('Validators', () => {
         'ABC-123',
       ],
     });
+    test({
+      validator: 'isLicensePlate',
+      args: ['en-IN'],
+      valid: [
+        'MH 04 AD 0001',
+        'HR26DQ0001',
+        'WB-04-ZU-2001',
+        'KL 18 X 5800',
+        'DL 4 CAF 4856',
+        'KA-41CE-5289',
+        'GJ 04-AD 5822',
+      ],
+      invalid: ['mh04ad0045', 'invalidlicenseplate', '4578', '', 'GJ054GH4785'],
+    });
   });
   it('should validate VAT numbers', () => {
     test({