Jango
Jango

Reputation: 5545

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-4521.

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

Upvotes: 0

Views: 102

Answers (3)

Chris B.
Chris B.

Reputation: 90201

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).

Upvotes: 4

Neel Basu
Neel Basu

Reputation: 12904

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

Upvotes: 0

Christian Hayter
Christian Hayter

Reputation: 31071

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

Upvotes: 6

Related Questions