regex - PHP Currency Regular Expression -


I'm trying to find a piece of regex to match a currency value.

I would like only numbers and 1 decimal point i.e

allowed

  • 10
  • 100
  • Match 100.00

I have searched and have tried a lot without any luck.

Hope you can give advice

  if (preg_match ('^ /? [0-9] + (?: [. [0- 9] +)? $ /', $ Theme) {# successful match} other {# match attempt failed}  

Side note : If you want to restrict how many decimal places you want, then do something like this:

  / ^ [0-9 ] + (?: \. [0- 9] {1,3})? $ / Im  

then

  100.000  

will match, while

  100.0001  

wont

If you need any type Urther help, post a comment.

PS If you can, then use the above number format. Basic functions are always better (faster and faster), otherwise this solution will serve you well.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -