Re: [PHP] PCRE regexp bug ?

This is a discussion on Re: [PHP] PCRE regexp bug ? within the PHP General forums, part of the PHP Programming Forums category; I believe I spoke too soon. If I use isset() then even if I leave the field empty it still ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 08-15-2003
tpc@csua.berkeley.edu
 
Posts: n/a
Default Re: [PHP] PCRE regexp bug ?


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...
> >
> >

>
>


Reply With Quote
  #2 (permalink)  
Old 08-15-2003
Curt Zirzow
 
Posts: n/a
Default Re: [PHP] PCRE regexp bug ?

* Thus wrote tpc@csua.berkeley.edu (tpc@csua.berkeley.edu):
>
> 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.


> > if (isset($_POST[MI]) && (preg_match('/^[[:alpha:]]{1,1}$/', $_POST[MI]) == 0))



That is because the browser is sending in the POST data:
MI=

Thus, php does set it to ''.

Use something like this instead:

if (strlen($_POST['MI'])) ...


btw, you should really quote your array keys.

HTH,


Curt
--
"I used to think I was indecisive, but now I'm not so sure."
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 02:35 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0