1

I need to create RegEx for two different states and I am having some trouble. Here are the requirements; one is for Washington DC and and the other for Delaware:

1) DISTRICT OF COLUMBIA (DC)
- Format: 9 Numeric (SSN) or 7 Numeric

2) DELAWARE (DE)
- Format: 1-7 Numeric

The RegEx I have for DC is ^(\d{7}|(\d{9})$ which doesnt seem to work.

I think I have the one for Delaware ^(\d{1,7})$

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Brian Benham
  • 69
  • 1
  • 9
  • Geez!! All these regex people jumping in this morning. You guys should swing by this question and see if you can help. http://stackoverflow.com/questions/4109147/how-can-i-find-everything-but-certain-phrases-with-a-regular-expression – Keng Nov 09 '10 at 14:30
  • ^(\d{7})|(\d{9}))$' appears to still have issue it is allowing me to enter 8 digits and also more than 9. I need it to only except either 7 digits or 9 digit but nothing else? – Brian Benham Nov 09 '10 at 14:37

4 Answers4

2

Another posiibility which should work aswell is:

^\d{7}(\d{2})?$
Sebastian Schmidt
  • 1,078
  • 7
  • 17
2

If you're still having problems try this. I moved the parenthesis around to enclose both conditions at once.

^(\d{7}|\d{9})$
Keng
  • 52,011
  • 32
  • 81
  • 111
1

For the DC expression, you have some syntax errors. Try:

^(\d{7})|(\d{9})
Keng
  • 52,011
  • 32
  • 81
  • 111
Samuel
  • 16,923
  • 6
  • 62
  • 75
1

In your DC regex, you've got a parenthesis after the 7, where there should be a closing curly bracket.

Gabriel Roth
  • 1,030
  • 1
  • 12
  • 31