Friday, 6 December 2013

How to enter only numbers in a TextBox in asp.net?

Suppose we have a TextBox named Mobile_No and we need to validate it so that user cannot enter wrong values in a TextBox.

We can use RegularExpressionValidator to validate Mobile_No. We just need to set the following  RegularExpressionValidator properties:

ID Mobile_Validator
ControlToValidate Mobile_No
ErrorMessage You can enter only numbers in Mobile Number
ValidationExpression ^([0-9])+$


Now if user enter any value other than numbers, it will show an error message.

(Note- You can write your own Error Message and Control Names.)

No comments:

Post a Comment