Link to home
Start Free TrialLog in
Avatar of Carolinat
Carolinat

asked on

How can I validate in a form an amount with two decimals like 12.98

Hi Guys,
Does any one have a function to validate a textbox with format like 99.99?
Also, if the value doesn't have cents or decimals as soon as the cursor leaves the textbox it should add .00 to the amount.
I'm working with ASP.

Thanks
Carol

Avatar of YZlat
YZlat
Flag of United States of America image

use this javascript function
ASKER CERTIFIED SOLUTION
Avatar of YZlat
YZlat
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
then call it from onchange event of a textbox:

<input type="text" name="text1" onchange="this.value = FormatCurrency(this.value);">
Avatar of Carolinat
Carolinat

ASKER

Hi YZlat,
I'm using a control for the textbox like this:
<asp:textbox id="txtValor1" runat="server">
How can I call the javascript function from here?
txtValor1.Attributes.Add("onchange", "javascript:this.value = FormatCurrency(this.value);")
place this code in Page_Load event
Excellent!!!
Thank you.
Carol