• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1339
  • Last Modified:

Regular Expression, 7 OR 9 digits

I have rarely used regex for more than very basic pattern matching.  Right now I am trying to verify drivers liscence numbers for each state.  

My problem is how do I check for 7 "^[\d]{7}$" or 9 "^[\d]{9}$" digits?  8 must fail.

"^[\d]{7,9}$"  Allows for 8 digits, which is unacceptable

Thanks


1234567 == true;
12345678 == false;
123456789 == true;
0
RPCIT
Asked:
RPCIT
1 Solution
 
RPCITAuthor Commented:
i think I figured it out,

^[\d]{7}([\d]{2})?$  Seems to work

Any reason it wouldn't?
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now