开发者

How i can create Reg Expression for the following number?

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

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

精彩评论

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