0

I have written a regex for testing both Indian vehicle chassis number and engine numberes like ME4KC093A98040032,- Chassis No

JF39E70321656 -Engine No

The regex that i'm written for matching these is,

/^([A-z]{2}[A-z0-9]{5,16})$/

But this regex matching other strings like JOHNDEO, or the strings which contains underscores.

Can anyone suggest me an advanced regex pattern to over come the issues i'm facing by satisfying the below given points.

  1. starts with Alpha bates(At least 2)

2.Only contains Alphanumerical

3.Restriction for special characters including underscore.

4.it should contain at least 2 alphabets and numbers.

5.minimum of 7 numbers and maximum of 18 numbers.

UPDATION:

modified the regex like

/^([A-Za-z]{2}[A-z0-9]{5,16})$/

But this could only satisfy the condition 3.

basith
  • 740
  • 4
  • 13
  • 26
  • `[A-z]` isn't the only problem. The interesting part is requiring 2+ letters and 2+ number, combined with the 7-18 char range limit. So I don't think this is a duplicate – Rhumborl Nov 27 '17 at 13:34
  • @Wiktor: can u just share the original question? – basith Nov 27 '17 at 13:34
  • 1
    https://stackoverflow.com/questions/4923380/difference-between-regex-a-z-and-a-za-z Replace `[A-z]` with `[A-Za-z]` – Wiktor Stribiżew Nov 27 '17 at 13:38
  • @WiktorStribiżew: but it can only solve the 'underscore' issue. – basith Nov 27 '17 at 13:40
  • OK I can't close vote now I voted for reopen, but a better dupe is .... https://stackoverflow.com/questions/2432416/regular-expression-for-indian-vehicle-number-in-javascript-and-php?rq=1 – Rhumborl Nov 27 '17 at 13:42
  • got the answer, **/^[A-z]{2}(?=.*\d)[a-zA-Z\d]{8,18}$/** This regex will satisfy all my scenarios. – basith Nov 28 '17 at 06:46

0 Answers0