Reputation: 117
If the user enters non-numeric and numeric values in a textbox, how do I keep only the numeric part?
Upvotes: 0
Views: 1917
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
Reputation: 38585
You could bind to the keydown event and if the key is not 0-9 set handled to true.
Upvotes: 1
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