Regular Expressions

  • Thread starter Thread starter Tom
  • Start date Start date
T

Tom

I have a text box with a max length set to 4 in my c#
ASP.NET page.

I wish to validate each character so that each one is a
digit.

I tried "\d" but this only validates the first character.

I tried "\d{4}?" but this expects me to enter in 4
digits. And if I enter in a 5 or 56 or 567 the validatoin
fires.

What kind of custom expression do I need create to allow
any digits to be entered and not all or none!
Valid entries
9
99
999
9999
invalid entries
99a9


Thanks

Tom
 
Try

\d+

which means match a digit, one or more times. If you didn't have the max
length set, you could use:

\d{1,4}

which means match from 1 to 4 digits.

--
Eric Gunnerson

Visit the C# product team at http://www.csharp.net
Eric's blog is at http://blogs.gotdotnet.com/ericgu/

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top