# VBForums CodeBank > CodeBank - JavaScript >  JavaScript - Currency Function

## Virus00110

Nice little US currency validation function.  Nice to use when wanting to validate a textbox on a web form that is for the user to enter a dollar amount.

Live working version 

Give it a try.  Hope you like it.  :Big Grin:

----------


## Travis G

You have a very fancy solution.

I just thought I would provide a one-line alternative for those that didn't need the extra features or overhead.



```
function isUSCurrency (sString) {
  return RegExp(/^\$?\d+(\.\d{2})?$/).test(String(sString).replace(/^\s+|\s+$/g, ""));
}
```

It can be modified to meet specific needs or tolerances.

----------


## tech-whiz

Thanks for the post Travis!  It was a great starting point.

I've tweaked Travis' RegExp a little to allow for commas:

bIsValidCurrency = RegExp(/^\$?[0-9\,]+(\.\d{2})?$/).test(String(txtValue).replace(/^\s+|\s+$/g, ""));

You could also allow for negative currency values with:

bIsValidCurrency = RegExp(/^-?\$?[0-9\,]+(\.\d{2})?$/).test(String(txtValue).replace(/^\s+|\s+$/g, ""));

----------

