validate currency

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

cityname= 5
coprice=25.99

i keep getting error that CityName.Text  is greater but it isnt????
Comment
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.

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

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

Commented:
Forgot the text attribute:

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

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

Or,

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

Or,

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