L
laredotornado
Hi,
I have a text field with the value "29..99" (notice the two dots
instead of one) and it is considered a float according to the
following logic. How would I rewrite the isFloat function so that the
above number fails validation?
if (!(isFloat(price) && parseFloat(price) > 0)) {
alert("Price field cannot be empty or zero!");
return;
}
function isFloat(s)
{
if (isInteger(s)) {
return true;
} // if
var n = trim(s);
return n.length>0 && !(/[^0-9.]/).test(n) && (/\.
\d/).test(n);
} // isFloat
function isInteger(s)
{
var n = trim(s);
return n.length > 0 && !(/[^0-9]/).test(n);
}
Thanks, - Dave
I have a text field with the value "29..99" (notice the two dots
instead of one) and it is considered a float according to the
following logic. How would I rewrite the isFloat function so that the
above number fails validation?
if (!(isFloat(price) && parseFloat(price) > 0)) {
alert("Price field cannot be empty or zero!");
return;
}
function isFloat(s)
{
if (isInteger(s)) {
return true;
} // if
var n = trim(s);
return n.length>0 && !(/[^0-9.]/).test(n) && (/\.
\d/).test(n);
} // isFloat
function isInteger(s)
{
var n = trim(s);
return n.length > 0 && !(/[^0-9]/).test(n);
}
Thanks, - Dave