Asif
Asif

Reputation: 5038

Want a regex for validating Indian Vehicle Number Format?

Hello everyone here...

I need to build up a swing application related to vehicle registration and in which i want to do input the vehicle number of indian standard, like:

MP 09 AB 1234

AH 17 FT 2387

UT 32 DR 6423

DL 01 C AA 1111

More Specifically,

Please if any one can help me? DocumentFilter type class can also help me.........

Upvotes: 21

Views: 64651

Answers (13)

Rohit Lalwani
Rohit Lalwani

Reputation: 579

If you are trying to verify the number by state RTO and number by Central (BH Series) try this :

    public static boolean validateNumberPlate(EditText numberPlate){
    final Pattern pattern1 = Pattern.compile("^[A-Z]{2}[\\\\ -]{0,1}[0-9]{2}[\\\\ -]{0,1}[A-HJ-NP-Z]{1,2}[\\\\ -]{0,1}[0-9]{4}$");   // for all states
    final Pattern pattern2 = Pattern.compile("^[0-9]{2}[\\\\ -]{0,1}BH[\\\\ -]{0,1}[0-9]{4}[\\\\ -]{0,1}[A-HJ-NP-Z]{1,2}$");   // for BH Series

    return (pattern1.matcher(numberPlate.getText().toString().trim()).matches() || pattern2.matcher(numberPlate.getText().toString().trim()).matches());
}

First Pattern is for the State RTO (Eg. RJ 00 XX 0000).

Second pattern is for BH Series (Eg. 00 BH 0000 XX).

Upvotes: 0

Rajesh Satvara
Rajesh Satvara

Reputation: 3964

Indian Vehicle number are like :

GJ 01 AA 1234 or KA 08 J 9192 or (New Bharat Series) like 22 BH 1234 AB or 22 BH 1234 A

You Can validate using these 2 regular expressions:

1) ^[A-Z]{2}[0-9]{2}[A-HJ-NP-Z]{1,2}[0-9]{4}$
2) ^[0-9]{2}BH[0-9]{4}[A-HJ-NP-Z]{1,2}$

As per RTO rules:

In RTO series Alphabet 'I' and 'O', 2 are excluded to avoid confusion with digits 0 or 1.

Upvotes: 8

Alix Axel
Alix Axel

Reputation: 154573

Based on the Wikipedia spec:

^[A-Z]{2}[ -][0-9]{1,2}(?: [A-Z])?(?: [A-Z]*)? [0-9]{4}$
  • The first two letters of the registration plate represent the State in which the vehicle is Registered.
  • The next two digit numbers are the sequential number of a district. Due to heavy volume of vehicle registration, the numbers were given to the RTO offices of registration as well.
  • The third part is a 4 digit number unique to each plate. A letter(s) is prefixed when the 4 digit number runs out and then two letters and so on.
  • In some states (such as the union territory of Delhi, and previously in Gujarat and Bihar ) the initial 0 of the district code is omitted; thus Delhi district 2 numbers appear as DL 2 not DL 02.
  • The National Capital Territory of Delhi has an additional code in the registration code: DL 01 C AA 1111

Upvotes: 47

Jithendra Kumar
Jithendra Kumar

Reputation: 31

AP-05-BJ-9353
TN-35-AB-638
MH-03-C-3843

Expression:

^[A-Z]{2}[-][0-9]{1,2}[-][A-Z]{1,2}[-][0-9]{3,4}$

Check the expression here: https://regexr.com/

Upvotes: 2

virat singh
virat singh

Reputation: 51

If you are looking for number plate(VRN) then use following regex

^[A-Z|a-z]{2}\s?[0-9]{1,2}\s?[A-Z|a-z]{0,3}\s?[0-9]{4}$

Upvotes: 5

ked
ked

Reputation: 2456

If you are looking for number plate in substring then use the following regex

.*?([A-Za-z]{2})(\d{2})([A-Za-z]{2})(\d{4}).*?

Upvotes: 0

Manoj Chavanke
Manoj Chavanke

Reputation: 111

//DL 01 C AA 1234
^[A-Z]{2}[ -]{0,1}[0-9]{2}[ -]{0,1}(?:[A-Z])[ -]{0,1}[A-Z]{1,2}[ -]{0,1}[0-9]{1,4}$

//MH 15 AA 1234
^[A-Z]{2}[ -]{0,1}[0-9]{2}[ -]{0,1}[A-Z]{1,2}[ -]{0,1}[0-9]{1,4}$

MVA 1234
^[A-Z]{3}[ -]{0,1}[0-9]{1,4}$

//MH 15 8008
^[A-Z]{2}[ -]{0,1}[0-9]{2}[ -]{0,1}[0-9]{1,4}$

with or without space :)

Upvotes: 0

Ketan sangle
Ketan sangle

Reputation: 436

^[A-Z]{2}\s[0-9]{1,2}\s[A-Z]{1,2}\s[0-9]{1,4}$ 

The above regex will work for the following types

DL 01 AA 1111

DL 0 AA 1111

DL 1 A 1111

DL 0 A 11

DL 01 AA 111

Upvotes: 0

Sachin Daingade
Sachin Daingade

Reputation: 11

-(BOOL) validateVehicleRegNumber:(NSString *)strNumber { //Example MH14DA8904

    NSString *validReg = @"[A-Z]{2}[0-9]{2}[A-Z]{2}[0-9]{4}";
    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", validReg];
    return [emailTest evaluateWithObject:strNumber];

}

Upvotes: 0

MoarCodePlz
MoarCodePlz

Reputation: 5176

Try this

^[A-Z]{2}\s[0-9]{2}\s[A-Z]{2}\s[0-9]{4}$

^ means start of string
[A-Z]{2} means 2 characters in the range of A through Z
\s means white space
[0-9]{2} means 2 characters in the range of 0 through 9
\s means white space
[A-Z]{2} means 2 characters in the range of A through Z
\s means white space
[0-9]{4} means 4 characters in the range of 0 through 9
$ means end of string

Based on what you said in your question this should be a very broad check against proper format, but I have a feeling that there are more specific regulations on how the license plates are numbered. Let me know if there are additional constraints for the regex.

Upvotes: 13

Asif
Asif

Reputation: 5038

Say for example if the user already entered a value like:

DL 

then the textbox did not take the next input any other than a integer or one more char as.....

DL C 

from here user can only enter a integer value............

So, in short what i want to do is to take the input only like that regex given by Alix

Based on the Wikipedia Specs

^[A-Z]{2}[ -][0-9]{1,2}(?: [A-Z])?(?: [A-Z]*)? [0-9]{4}$

Upvotes: 0

Fredrik Pihl
Fredrik Pihl

Reputation: 45672

^[A-Z]{2} [0-9]{2} [A-Z]{2} [0-9]{4}$

See http://en.wikipedia.org/wiki/Vehicle_registration_plates_of_India

Looks like the format is a bit more complex than stated in your question...

Upvotes: 2

K6t
K6t

Reputation: 1845

just check it out for whitespace only...

  function isValidNumber($Number){
         $pattern = "^[a-zA-z]{2}\s[0-9]{2}\s[0-9]{4}$";
         if (eregi($pattern, $Number)){
            return true;
         }
         else {
            return false;
        }
    }

Upvotes: 0

Related Questions