Sign in | Join
Last post 03-25-2008 3:22 PM by smcirish. 8 replies.
Sort Posts: Oldest to newest Newest to oldest
how to validate a textbox to accept only numbers from 0-9.other than letters
Hi,
use a RangeValidator control like this:
<asp:TextBox runat=server ID=TextBox1></asp:TextBox> <asp:RangeValidator runat=server ID=RangeValidator1 ControlToValidate=TextBox1 MaximumValue=9 MinimumValue=0 ErrorMessage="*" Type="Integer"></asp:RangeValidator>
Grz, Kris.
I would use a RegularExpressionValidator like so:
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="TextBox1" ErrorMessage="Must be all numbers" ValidationExpression="^\d+$"></asp:RegularExpressionValidator>
Oops I misinterpreted the question as I thought you would only need a cipher between 0 - 9. If you need indeed a sequence of ciphers and you know the highest possible value you can also use that to set the MaximumValue property to that.
do i need to write anythg in the back end C# code?
joynee:do i need to write anythg in the back end C# code?
No, just add the validation control you need, set the correct properties and you're good to go.
No, the Validator controls do everything for you... Does it not working?
thanq its working
You can use a range validation check.
For other kinds of data cleanup/special characters, see this post.
http://forums.asp.net/t/1174006.aspx