RE: [PHP] Why would this eregi() function not work?
... escaping isn't necessary. Thanks so much for all the helpful advice! Okay, included the + character, and removed the escaping. And I know I'm supposed to checking into preg_match, but I'm looking at this as an opportunity to learn about regular expressions, so I still have a question. I'm confused why hyphens wouldn't still need escaping. Hyphens are used to express a range of characters. If there's a hyphen there, won't PHP think I'm looking for a range from nothing to nothing? Or is it clever enough to figure out what's going on? (!eregi('[EMAIL PROTECTED]', $email) -- Cheers! Dave G [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Why would this eregi() function not work?
On Fri, Nov 14, 2003 at 04:32:35PM +0900, Dave G wrote: : : ... escaping isn't necessary. : : Thanks so much for all the helpful advice! : Okay, included the + character, and removed the escaping. And I know I'm : supposed to checking into preg_match, but I'm looking at this as an : opportunity to learn about regular expressions, so I still have a : question. I'm confused why hyphens wouldn't still need escaping. Hyphens : are used to express a range of characters. If there's a hyphen there, : won't PHP think I'm looking for a range from nothing to nothing? Or is : it clever enough to figure out what's going on? : (!eregi('[EMAIL PROTECTED]', $email) The last part of your pattern needs to be changed because it allows for a top-level domain to contain numbers and hyphens. Currently, such a thing does not exist. Also, the 2nd part of your pattern allows for a 2nd-level domain to start and end with a hyphen, which is also disallowed. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Why would this eregi() function not work?
Dave -- ...and then Dave G said... % % ... escaping isn't necessary. % % Thanks so much for all the helpful advice! You're quite welcome :-) % Okay, included the + character, and removed the escaping. And I know I'm Good! % supposed to checking into preg_match, but I'm looking at this as an % opportunity to learn about regular expressions, so I still have a Sounds good. Note that preg_match will use the same regexp syntax, too. % question. I'm confused why hyphens wouldn't still need escaping. Hyphens % are used to express a range of characters. If there's a hyphen there, Yep. % won't PHP think I'm looking for a range from nothing to nothing? Or is If you put the hyphen between two things, yes. If not, no. % it clever enough to figure out what's going on? It's not only a PHP thing; just about any *NIX tool or programming language that understands extended regexps at all will behave that way. I truly wish that I could point you to a canonical reference on the matter, but such a thing escapes me. I'm fairly sure you'd be able to find it -- or a reference to it -- within the GNU space, so perhaps the man page for egrep or such would help. I did a quick google search and found http://www.opengroup.org/onlinepubs/7908799/xbd/re.html which may be helpful. In addition, there is a regex package by Henry Spencer which seems to be everyone's reference point. % (!eregi('[EMAIL PROTECTED]', $email) % % -- % Cheers! % Dave G % [EMAIL PROTECTED] HTH HAND :-D -- David T-G * There is too much animal courage in (play) [EMAIL PROTECTED] * society and not sufficient moral courage. (work) [EMAIL PROTECTED] -- Mary Baker Eddy, Science and Health http://justpickone.org/davidtg/ Shpx gur Pbzzhavpngvbaf Qrprapl Npg! pgp0.pgp Description: PGP signature
RE: [PHP] Why would this eregi() function not work?
The last part of your pattern needs to be changed because it allows for a top-level domain to contain numbers and hyphens. Currently, such a thing does not exist. Okay... I can change that... (!eregi('[EMAIL PROTECTED]', $email)) Also, the 2nd part of your pattern allows for a 2nd-level domain to start and end with a hyphen, which is also disallowed. Hmmm... but I don't think I want to get too strict. I mean, if I can write the code to make sure the domain doesn't start or end with the hyphen, but can have one in between, then cool. But I think that would require more expression footwork than I'm capable of at this point. I truly wish that I could point you to a canonical reference on the matter, but such a thing escapes me... http://www.opengroup.org/onlinepubs/7908799/xbd/re.html ... which may be helpful. That's a pretty hefty read, but it looks useful to have around for a reference. Thanks! -- Cheers! Dave G [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Why would this eregi() function not work?
PHP Gurus, I have an eregi() function that I'm using to validate emails that users enter into a form. I pretty much took it directly from the book PHP and MySQL Web Development. It looks like this: (!eregi('[EMAIL PROTECTED]', $email) For the most part it's working fine. But recently a user tried to enter in his email address and it got rejected by this script. After a little experimentation, it looks like it's the hyphen in the first part of his address that's causing it to be rejected. His email address looks like: [EMAIL PROTECTED] If I remove the hyphen, like so: [EMAIL PROTECTED] Then it passes. Looking at my eregi() function, I've included hyphens as a valid character, and escaped them out with slashes in order that they work within the square brackets. Why would this email be rejected? -- Cheers! Dave G [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Why would this eregi() function not work?
Dave G wrote: PHP Gurus, I have an eregi() function that I'm using to validate emails that users enter into a form. I pretty much took it directly from the book PHP and MySQL Web Development. It looks like this: (!eregi('[EMAIL PROTECTED]', $email) 1. Special characters within brackets do not need to be escaped. [.] will match a period. 2. If you're going to include a hyphen within brackets, it needs to be the last character, otherwise you're signifying a range. [a-z] is a through z. [a-] is a or a hyphen. 3. I don't think a hyphen is even legal in an email address... ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals www.phparch.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Why would this eregi() function not work?
Dave -- ...and then Dave G said... % % PHP Gurus, % I have an eregi() function that I'm using to validate emails % that users enter into a form. I pretty much took it directly from the % book PHP and MySQL Web Development. It looks like this: % (!eregi('[EMAIL PROTECTED]', $email) 1) Constructing an all-compatible email expression is darned near impossible. See the archives for a recent discussion of this. 2) Sure enough, you don't allow + extensions in yours. Neener neener :-) 3) You might check out preg_match, which the manual says is often faster than ereg(). 4) To include '-' in a range list, put it last in the range. HTH HAND :-D -- David T-G * There is too much animal courage in (play) [EMAIL PROTECTED] * society and not sufficient moral courage. (work) [EMAIL PROTECTED] -- Mary Baker Eddy, Science and Health http://justpickone.org/davidtg/ Shpx gur Pbzzhavpngvbaf Qrprapl Npg! pgp0.pgp Description: PGP signature
RE: [PHP] Why would this eregi() function not work?
2) Sure enough, you don't allow + extensions in yours. Neener neener :-) Is + a legal character in emails? 3) You might check out preg_match, which the manual says is often faster than ereg(). Will look into it. Thanks for the tip. 4) To include '-' in a range list, put it last in the range. So then it would look like this: (!eregi('[EMAIL PROTECTED]', $email) Is that right? 1. Special characters within brackets do not need to be escaped. [.] will match a period. So then I could make it: (!eregi('[EMAIL PROTECTED]', $email) Correct? 3. I don't think a hyphen is even legal in an email address... If it wasn't, the user couldn't have emailed me to tell me that he wasn't having success in registering on my form. Or could he? -- Cheers! Dave G [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Why would this eregi() function not work?
Dave -- ...and then Dave G said... % % 2) Sure enough, you don't allow + extensions in yours. % Neener neener :-) % % Is + a legal character in emails? Yep. IIRC sendmail and postfix use it for their extensions like qmail uses (by default) a - (but qmail can use whatever you want). See 1) again :-) % % 3) You might check out preg_match, which the manual says is % often faster than ereg(). % % Will look into it. Thanks for the tip. Sure thing! % % 4) To include '-' in a range list, put it last in the range. % % So then it would look like this: % (!eregi('[EMAIL PROTECTED]', $email) % Is that right? Yes, except change all \.\- to .- since escaping isn't necessary. % % 1. Special characters within brackets do not need to be escaped. [.] % will match a period. % % So then I could make it: % (!eregi('[EMAIL PROTECTED]', $email) % Correct? Almost there. % % 3. I don't think a hyphen is even legal in an email address... % % If it wasn't, the user couldn't have emailed me to tell me that he % wasn't having success in registering on my form. Or could he? I already poked at him about that. Look at my address, for instance ;-) % % -- % Cheers! % Dave G % [EMAIL PROTECTED] HTH HAND :-D -- David T-G * There is too much animal courage in (play) [EMAIL PROTECTED] * society and not sufficient moral courage. (work) [EMAIL PROTECTED] -- Mary Baker Eddy, Science and Health http://justpickone.org/davidtg/ Shpx gur Pbzzhavpngvbaf Qrprapl Npg! pgp0.pgp Description: PGP signature