File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Validating an Amount Field Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Validating an Amount Field" Watch "Validating an Amount Field" New topic

Validating an Amount Field

Alec Lee
Ranch Hand

Joined: Jan 28, 2004
Posts: 569
I want to make sure a text field is any non-negative numeric value with 2 or less decimal point not less then say $100000. What is the simplest combination of the standard rules/regular expressions to achieve this with the validator?

Also, if I want to allow the user to optionally add commas like 10,000. What would the simplest combination of rules.

I guess the 'mask' rule has to be used with some regular expression. But my knowledge of regexpr is very little!

Thx for any advice.
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
Here are some expressions that I put together a while ago. I tested them at the time and they have been in use for a few years so I hope they work. Like you, I don't know much about regular expressions, but I was smart enough to add a comment.

- Brent
I agree. Here's the link:
subject: Validating an Amount Field
jQuery in Action, 3rd edition