0

I need the regex in PHP for the currency with decimal.

I would like to match only numbers with decimal points. There should be 2 numbers after the decimal point.

I am using preg_match('/^[0-9]+(?:\.[0-9]+)?$/', $amt). However, in this amount 100 is also validating correctly, which should not be the case.

Correct

100.00

5676.00

Wrong

Alpha Characters

100

100,00

+/- 100

Thank you in advance.

Adi
  • 155
  • 1
  • 1
  • 9
  • `\d+\.\d{2}` maybe... Could even add word boundaries `\b\d+\.\d{2}\b` – AbraCadaver Nov 20 '19 at 21:35
  • Looks like you are looking to create a regex, but do not know where to get started. Please check [Reference - What does this regex mean](https://stackoverflow.com/questions/22937618) resource, it has plenty of hints. Once you get some expression ready and still have issues with the solution, please edit the question with the latest details and we'll be glad to help you fix the problem. – Wiktor Stribiżew Nov 20 '19 at 21:39

0 Answers0