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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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:
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’.