sakthivignesh
sakthivignesh

Reputation: 117

How do I validate a textbox to only contain numbers?

If the user enters non-numeric and numeric values in a textbox, how do I keep only the numeric part?

Upvotes: 0

Views: 1917

Answers (3)

Degan
Degan

Reputation: 989

Set the property "CausesValidation" to true. Set your validation to accept only an int or whatever sort of number you are looking for.

Perhaps see: Number validation in required field validator

Upvotes: 3

Peter
Peter

Reputation: 38585

You could bind to the keydown event and if the key is not 0-9 set handled to true.

Upvotes: 1

waqasahmed
waqasahmed

Reputation: 3845

You can use RegularExpressionValidator

Validate it against your control, with the validation Expression of {0:d} to permit only digits or {0:w} for letters and numbers as well.

Upvotes: 1

Related Questions