Hello all
I have 2 textboxes on my aspx site which I want to validate.
I want to make sure that the second textbox value is higher than the first one.
For example:
The user inputs 40 in the first textbox and 20 in the second.
This will give an error since 20 is less than 40.
But if the user types 40 and 60 it should work.
It should also be numbers only :)
Any ideas?
Cheers! :-D
4 replies to this topic
#1
Posted 16 November 2009 - 07:10 AM
|
|
|
#2
Posted 16 November 2009 - 07:54 AM
I'm not sure how you handle request variables but this is easily accomplished with ASP, PHP, or even JS.
if(text1 > text2) {
return "error!";
}
#3
Posted 16 November 2009 - 07:56 AM
Hi
Thanks for the answer but I found a soloution
Thanks for the answer but I found a soloution
<asp:CompareValidator ID="CompareValidator1" runat="server" ErrorMessage="CompareValidator" ControlToValidate="TextBox2" ControlToCompare="TextBox1" Operator="GreaterThan"> </asp:CompareValidator>
#4
Posted 04 March 2010 - 07:40 AM
well glad u found the answer,but if you are using this just to make sure user enters numbers correctly try this
also the correct control to use is the RangeValidator , with the controll to valid set to TextBox1 and Control to comparewith set to TextBox2
TryParse.Int16(TextBox1.Text) < TryParse.Int16(TextBox2.Text)
also the correct control to use is the RangeValidator , with the controll to valid set to TextBox1 and Control to comparewith set to TextBox2
#5
Posted 02 April 2010 - 05:49 AM
If you want to ensure that only numbers are entered you can easily do this by using the regularexpressionvalidator control with it's Validation Expression set to \d+
You may also want to include validation in javascript on the client to prevent a round trip to the server, for this you can use the following code:
// mystring is equal to whatever was entered in the textbox by the user
if(mystring.match(\d+))
{
\\your code if test was successful
}
else
{
alert("Please enter a number");
}
You may also want to include validation in javascript on the client to prevent a round trip to the server, for this you can use the following code:
// mystring is equal to whatever was entered in the textbox by the user
if(mystring.match(\d+))
{
\\your code if test was successful
}
else
{
alert("Please enter a number");
}
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top










