Jump to content

RequiredFieldValidator price range

- - - - -

  • Please log in to reply
4 replies to this topic

#1
Dumpen

Dumpen

    Newbie

  • Members
  • PipPip
  • 14 posts
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

#2
BlaineSch

BlaineSch

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,448 posts
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
Dumpen

Dumpen

    Newbie

  • Members
  • PipPip
  • 14 posts
Hi

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
gokuajmes

gokuajmes

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 518 posts
well glad u found the answer,but if you are using this just to make sure user enters numbers correctly try this

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
kotg2

kotg2

    Newbie

  • Members
  • Pip
  • 4 posts
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");
}




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users