开发者

How i can create Reg Expression for the following number?

In c#, i gotta verify user inputs. Can someone tell me what will be the reg ex in order to verify this expression 12345开发者_Python百科-4521.

<12345> = Any five digits only
<-> = only hyphen
<4521> = Any four digits only but last digit should either be 0 or 1.


^\d{5}-\d{3}[01]$


This should do it:

\d{5}-\d{3}[01]

Explanation:

  • The \d matches any digit from 0 through 9
  • The [01] matches a 0 or 1
  • The {5} and {3} tells it to match exactly that number of the previous expression

This is pretty basic stuff. When you get a chance, you should read a good tutorial, which covers this (and much more).


The Following Should work: \d{5}\-\d{3}[01]

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜