Surya sasidhar
Surya sasidhar

Reputation: 30313

How do I implement numeral-only validation for a TextBox?

I would like to restrict the contents of a TextBox to contain only five digits. Could you please suggest a way to do so?

Upvotes: 0

Views: 273

Answers (4)

Muhammad Akhtar
Muhammad Akhtar

Reputation: 52241

here is validation expression ^\d{1,5}$

But its preferable to use RangeValidator

 <asp:RangeValidator ID="rngv" runat="server" ControlToValidate="txt"
      ErrorMessage="1 to 99999 is Allowed" MaximumValue="99999" MinimumValue="1"
      SkinID="validation" Type="Integer"></asp:RangeValidator>

Upvotes: 3

pankaj
pankaj

Reputation:

put this in expression ^\d{5}$

Upvotes: 0

rahul
rahul

Reputation: 187050

What about

^\d*[0-9](|.\d*[0-9]|,\d*[0-9])?$

that permits all decimal numbers.

Edit:

^\d{1,5}$

Eact 5 digits

^\d{5}$

Upvotes: 1

PhilPursglove
PhilPursglove

Reputation: 12589

Rather than playing around with regular expressions and validators I would have said the easiest way to implement this is to use the FilteredTextBox extender from the Ajax ControlToolkit which has the built-in capability to restrict entry to just numbers.
Then set the MaxLength property on the TextBox to 5.

Upvotes: 0

Related Questions