i have this regular expression: ^\$?(\d{1,3}(\,\d{3})*|(\d+))(.\d{2})?$
however it is failing when i have an amount such as this: 41022095.6
anything i am missing?
i have this regular expression: ^\$?(\d{1,3}(\,\d{3})*|(\d+))(.\d{2})?$
however it is failing when i have an amount such as this: 41022095.6
anything i am missing?
Your regular expression expects either no decimal point, or a decimal point followed by two decimal digits. It depends on what you want, but you could make your regex match your suggested input by doing this:
^\$?(\d{1,3}(\,\d{3})*|(\d+))(\.\d{1,2})?$
I changed the {2}
near the end to {1,2}
to allow one or two decimal digits after the decimal point. I also changed the .
to \.
because a plain .
in a regex means "match any character".
This part: "(.\d{2})?"
says that your number can optionally end in "dot followed by two digits", but it's optional. Since you don't have "dot followed by two digits" anywhere in your example and nothing else that allows a dot, it is not matched.
Also, ass duffymo pointed out, you probably want to escape the dot to make it match the full stop instead of any character.