validate currency

Wigging used Ask the Experts™
 If CityName.Text > coprice.Text Then

cityname= 5

i keep getting error that CityName.Text  is greater but it isnt????
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
if  Cstr(CityName.Text) > cstr(coprice.Text) then  
something like this maybe

<asp:TextBox id="TextBox1" runat="server" />
<asp:RequiredFieldValidator id="RVF1" runat="server" ControlToValidate="TextBox1"  
   ErrorMessage="Required" Display="Dynamic" />
<asp:CompareValidator id="CheckFormat1" runat="server" ControlToValidate="TextBox1" Operator="DataTypeCheck"  
   Type="Currency"  Display="Dynamic" ErrorMessage="Illegal format for currency" />
<asp:RangeValidator id="RangeCheck1" runat="server" ControlToValidate="TextBox1"
   Type="Currency" Minimum="1.00" Maximum="999.99" ErrorMessage="Out of range" Display="Dynamic" />
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

Because you want to compare numbers, not text, use this:

   if cdbl(CityName.Text) > cdbl(coprice) then

Forgot the text attribute:

   if cdbl(CityName.Text) > cdbl(coprice.text) then
Try this:

If CDec(CityName.Text) > CDec(CoPrice.Text) Then


If Decimal.Parse(CityName.Text) > Decimal.Parse(CoPrice.Text) Then


If Double.Parse(CityName.Text) > Double.Parse(CoPrice.Text) Then

Or, if you really want it safe by checking if data in textbox can be converted, use TryParse.  My example below is for Decimal but you can also use for Double.  Just Replace the word Double to the Decimal if you want to test it with Double.

Dim CityNameDec As Decimal
Dim CoPriceDec As Decimal
If Decimal.TryParse(CityName.Text,CityNameDec) And Decimal.TryParse(CoPrice.Text,CoPriceDec) Then
    If CityNameDec > CoPriceDec Then

    End If
End If

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial