Link to home
Start Free TrialLog in
Avatar of Westside2004
Westside2004Flag for United States of America

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
Avatar of tonsofpcs
tonsofpcs
Flag of United States of America image

psuedocode:
if not instring(blah,".") {
removespaces(blah)
blah = blah + ".00"
}
Avatar of Westside2004

ASKER

Thanks,

Looking for actual code however, I get the concept.

-ws
ASKER CERTIFIED SOLUTION
Avatar of steveberzins
steveberzins

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