Adjusting a RegEx to require 2 digits after an optional decimal?
I believe I've found the "perfect" Regular Expression to check against for
currency in jQuery Validate, except it seems to allow the user to put a
single lone decimal at the end or a decimal with a single digit after.
Matches: 700. and 3.0
The Regex:
^\$?([1-9]{1}[0-9]{0,2}(\,[0-9]{3})*(\.[0-9]{0,2})?|[1-9]{1}[0-9]{0,}(\.[0-9]{0,2})?|0(\.[0-9]{0,2})?|(\.[0-9]{1,2})?)$
I've been playing with it in http://gskinner.com/RegExr/ but can't seem to
modify it in the right places to fix my decimal issue.
Currently it matches everything I need it to:
700,000
700,000.00
700000
No comments:
Post a Comment