preg_match or not?
| From: | Steve Fitzgerald | Date: | Sun, 07 Jul 2002 06:09:51 +0000 |
| Subject: | preg_match or not? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-105933@lists.php.net to get a copy of this message | ||
I have been struggling for a couple of hours now trying to write a
preg_match expression to validate a dollar amount - the user may or may
not put in the decimals so I want to allow only digits plus a possible
period followed by two more digits. My eyes are now swimming and I just
can't seem to get right. This is what I have at the moment:
if (!preg_match("/[\d]+([\.]{1}[\d]{2})?/", $form_data[amount])) //
wrong amount
but it still allows invalid input. Can anyone help or is there a better
way to do it?
Thanks
Steve