Re: Re: regex problem
| From: | Daniel J. Rychlik | Date: | Sat, 31 May 2003 20:29:34 +0000 |
| Subject: | Re: Re: regex problem | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-149677@lists.php.net to get a copy of this message | ||
I had no idea their was a is_numeric function(). Ill check it out. Its
probably a lot better to use then trying to preg_match()/
Many thanks
----- Original Message -----
From: "Monty" <monty3@hotmail.com>
To: <php-general@lists.php.net>
Sent: Saturday, May 31, 2003 3:21 PM
Subject: [PHP] Re: regex problem
> I don't understand what it is you're trying to accomplish, so, it's hard
to
> offer a solution. If you just want to verify whether or not a variable
> contains numeric data, why not just use the is_numeric() function:
>
> http://us4.php.net/manual/en/function.is-numeric.php
>
> preg_match() will return TRUE if it finds the pattern ANYWHERE in the
> string, so, that's why "asdf789" passes the test because it contains
digits,
> whereas 'asdf' won't pass the test because the numbers 0-9 can't be found
> anywhere in that string.
>
> If you want the entire string to be tested for digits, you need to add the
> length of the string to the regex pattern:
>
> $length = strlen($data);
> preg_match("[0-9]{$length}", $data);
>
> Monty
>
> > From: drychlik@tcsconsult.com (Daniel J. Rychlik)
> > Newsgroups: php.general
> > Date: Sat, 31 May 2003 13:46:44 -0500
> > To: <php-general@lists.php.net>
> > Subject: 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
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>