Regular Expression Help

  • Thread starter Thread starter tdavisjr
  • Start date Start date
T

tdavisjr

Anyone can give me a quick RegEx pattern that would match a 7 or 10
digit number. This is not a range; but exactly 7 or 10. I'm beating
my head over this, nothing I am doing works. Thanks
 
I believe this works:

^\d{7}(\d{3})?$

it makes the last 3 digits optional (as a group)

Karl
 
Hi,

You will probably find RegExlib.com to be very helpful. It has a
library of custome regular expressions. There is also a tool that
allows you to test your own regular expressions.
 
Thanks Karl. That seem to work. I probably need to adjust my thinking
when doing RegEx's. I was trying to do something like this: (\d{7}) |
(d{10}) when it was either or. I never thought about making the last
part optional as a group.

And Tod, Thanks for the reference. I did visit this site and used its
tester, however, I searched the database and I could find a simple
example for what I wanted.
 
That works too, you just have your parenthesis in the wrong place:

^(\d{7}|\d{10})$

Karl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top