Re: PCRE regexp bug ?
| From: | tpc at csua dot berkeley dot edu | Date: | Fri, 15 Aug 2003 20:20:49 +0000 |
| Subject: | Re: PCRE regexp bug ? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-159756@lists.php.net to get a copy of this message | ||
I believe I spoke too soon. If I use isset() then even if I leave the
field empty it still returns true. I am trying to view the documentation for
this function but php.net seems to be timing out now.
On Fri, 15 Aug 2003 tpc@csua.berkeley.edu wrote:
>
> Thank you. I did the following:
>
> if (isset($_POST[MI]) && (preg_match('/^[[:alpha:]]{1,1}$/', $_POST[MI]) ==
> 0))
>
> and zero is caught.
>
> On Fri, 15 Aug 2003, CPT John W. Holmes wrote:
>
> > From: <tpc@csua.berkeley.edu>
> >
> > > I use preg_match to validate the Middle Initial field of a form and so far
> > > it works, except yesterday a user submitted a "0" (zero) as a middle
> > > initial! My regexp is:
> > >
> > > if (!empty($_POST[MI]) && (preg_match('/^[[:alpha:]]{1,1}$/',
> > > $_POST[MI])
> > == 0))
> > >
> > > I tested it with 0-9 and my regexp catches every digit except 0.
> > Curious...
> >
> > empty("0") is going to be true. So, !empty("0") is going to be false,
> > so you
> > won't "catch" the zero.
> >
> > ---John Holmes...
> >
> >
>
>