Westside2004
asked on
Numeric/Money Validation, My function is not working as expected
Hi,
I have this function that sort of works. It validates this field where I want users to type in a "dollar" amount.
function isMoney(elm) {
str = elm.replace("$", "");
str = str.replace(",",""); //regex=/^[a,b,c,x,y,z]{3} \d{3}$/;
var myexp = /^\d+\.\d{0,2}$/;
var regex = new RegExp(myexp);
return regex.test(str);
}
This works fine
$45.00
This does not
$45
Is there a way to have it so if the user enters just 34 it will add the .00 if it does NOT exist already.
My database has a column with a datatype of Money (using sql server).
Thanks
-ws
I have this function that sort of works. It validates this field where I want users to type in a "dollar" amount.
function isMoney(elm) {
str = elm.replace("$", "");
str = str.replace(",",""); //regex=/^[a,b,c,x,y,z]{3}
var myexp = /^\d+\.\d{0,2}$/;
var regex = new RegExp(myexp);
return regex.test(str);
}
This works fine
$45.00
This does not
$45
Is there a way to have it so if the user enters just 34 it will add the .00 if it does NOT exist already.
My database has a column with a datatype of Money (using sql server).
Thanks
-ws
ASKER
Thanks,
Looking for actual code however, I get the concept.
-ws
Looking for actual code however, I get the concept.
-ws
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
if not instring(blah,".") {
removespaces(blah)
blah = blah + ".00"
}