admin管理员组

文章数量:1287283

I am a novoice in regular experssion. I need a regex for 8 or 17 digit only validation.

its for a vehicle VIN validation. system should accept for 8 or 17 digit vin with small and camel case alphabets

Could someoone please help.....

I am a novoice in regular experssion. I need a regex for 8 or 17 digit only validation.

its for a vehicle VIN validation. system should accept for 8 or 17 digit vin with small and camel case alphabets

Could someoone please help.....

Share Improve this question edited Jul 20, 2012 at 8:33 Punith Raj asked Jul 20, 2012 at 8:22 Punith RajPunith Raj 2,1956 gold badges27 silver badges48 bronze badges 3
  • i dint try dude.. i have not done any regex before – Punith Raj Commented Jul 20, 2012 at 8:27
  • 6 @PunithRaj: Then read up on them (there's no shortage of material). You want to learn to fish, not be given fish. – T.J. Crowder Commented Jul 20, 2012 at 8:28
  • 4 Stackoverflow is for educating, not a free freelance coder service. "I am a noob" is not an excuse, everything you said still reads to me as "Here's requirements, send me teh codez". Which I would expect to hear from my boss (not literally ofc). – Esailija Commented Jul 20, 2012 at 8:32
Add a ment  | 

3 Answers 3

Reset to default 11

Just consider 8 digits and optionally 9 more digits

/^\d{8}(\d{9})?$/

Meaning is:

^        start of string
\d       a digit
{n}      repeat n times
(...)?   optional part
$        end of string

use this regex ^((\d{8})|(\d{17}))$

for that you could just put two regexes together:

/^(\d{8}|\d{17})$/

When you have multiple distinct possibilities you can always do

/(one-regex|another-regex)/

本文标签: javascript8 or 17 digit only Regular expressionStack Overflow