Re: regex problem
| From: | Jim Lucas | Date: | Sat, 31 May 2003 23:04:34 +0000 |
| Subject: | Re: regex problem | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-149685@lists.php.net to get a copy of this message | ||
Are you wanting the $_POST['nums1'] to have only numbers, -, ., #, : ????
Is this what you are trying to match. if so, try this.
if ( preg_match("/[^0-9\#\:\.\-]/", $_POST['nums1']) ) {
throw error()
}
This will match anything that is not a number or one of the other special
chars that are in the pattern to be matched.
Therefor, if it does find anything that is not in the pattern to be matched
it will return true and then it will enter the if statement instead of
skipping over it.
Jim Lucas
----- Original Message -----
From: "Daniel J. Rychlik" <drychlik@tcsconsult.com>
To: <php-general@lists.php.net>
Sent: Saturday, May 31, 2003 11:46 AM
Subject: [PHP] regex problem
Hello,,
I have a preg_match issue matching numbers. I am currently using
!preg_match ('/([0-9\-\.\#:])/', $_POST['nums1']
throw error[]
This fails if you use something like ' asdf ' but if you use ' asdf789 ' it
passes false and does not throw an error.
This is not the obvious solution.... I know its a problem in my regular
expression. Should I ONLY be using
' /([0-9])/ ' , ?
Thanks in advance.
Daniel