shanuragu
07-01-2003, 08:51 AM
HI
How can I validate a decimal field?
var re = /^\d{2}\.\d{2}/ ;
var ucost=document.currency.unitcost.value;
if (!(re.test(ucost)))
{
alert("Decimal field enter value in .00 format ...");
document.currency.unitcost.focus();
return false;
}
The above code validates only for two digit number with two digits after decimal point.
Number after decimal point is fixed to 2 digits, but digits before decimal point can be of any number of digits.
How can I generalise the above code for any number of digits before decimal point?
ShaRa
How can I validate a decimal field?
var re = /^\d{2}\.\d{2}/ ;
var ucost=document.currency.unitcost.value;
if (!(re.test(ucost)))
{
alert("Decimal field enter value in .00 format ...");
document.currency.unitcost.focus();
return false;
}
The above code validates only for two digit number with two digits after decimal point.
Number after decimal point is fixed to 2 digits, but digits before decimal point can be of any number of digits.
How can I generalise the above code for any number of digits before decimal point?
ShaRa