Avatar of Westside2004
Westside2004
Flag 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
JavaScript

Avatar of undefined
Last Comment
steveberzins

8/22/2022 - Mon
tonsofpcs

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

ASKER
Thanks,

Looking for actual code however, I get the concept.

-ws
ASKER CERTIFIED SOLUTION
steveberzins

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23