Re: [PHP] PCRE regexp bug ?
* Thus wrote [EMAIL PROTECTED] ([EMAIL PROTECTED]): > > 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." -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
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 [EMAIL PROTECTED] 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: <[EMAIL PROTECTED]> > > > > > 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... > > > > > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PCRE regexp bug ?
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: <[EMAIL PROTECTED]> > > > 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... > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PCRE regexp bug ?
* Thus wrote Curt Zirzow ([EMAIL PROTECTED]): > * Thus wrote [EMAIL PROTECTED] ([EMAIL PROTECTED]): > > > > 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... > > actaually 0-9 will never match that regexp. Oops after reading my post to your post I see that is what you wanted. sorry. the 0 problem can be fixed by checking strlen($_POST[MI]) or isset() instead of !empty(). Curt -- "I used to think I was indecisive, but now I'm not so sure." -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PCRE regexp bug ?
* Thus wrote [EMAIL PROTECTED] ([EMAIL PROTECTED]): > > 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... actaually 0-9 will never match that regexp. print preg_match('/^[[:alpha:]]{1,1}$/', '1'); yields: 0 The reason is that 0-9 is not alpha. You should use [[:alnum:]] instead. Or better yet /^\w{1,1}$/ HTH, Curt -- "I used to think I was indecisive, but now I'm not so sure." -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PCRE regexp bug ?
From: <[EMAIL PROTECTED]> > 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... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PCRE regexp bug ?
Not an answer but '/^[[:alpha:]]{1,1}$/' could be writen as '/^[[:alpha:]]$/' [EMAIL PROTECTED] wrote: 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... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PCRE regexp bug ?
- Original Message - From: <[EMAIL PROTECTED]> > > 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... > Maybe it thinks it's the letter O, have you tried using a font that puts a line through the zero;-) [sorry couldn't resist] Cheers, Greg. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PCRE regexp bug ?
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... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php