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;
LVL 6
RPCITAsked:
Who is Participating?
 
RPCITConnect With a Mentor Author Commented:
i think I figured it out,

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

Any reason it wouldn't?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.