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
3 Answers
Reset to default 11Just 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
版权声明:本文标题:javascript - 8 or 17 digit only Regular expression - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741306300a2371388.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论