Want a regex for validating Indian Vehicle Number Format?

Viewed 49501

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.........

12 Answers

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}$

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.

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/

-(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];

}

^[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

//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 :)

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}).*?
Related