开发者

I am new to RegEx and I need to create a few RegEx scripts for a Drivers License field

开发者 https://www.devze.com 2023-01-24 18:17 出处:网络
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:

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)

- 开发者_StackOverflow社区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})$


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

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


Another posiibility which should work aswell is:

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


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


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

^(\d{7})|(\d{9})
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号