RE: [PHP] email validation regex
reel 'em in john but remember.. there's top/bottom/side/spoon/etc for more, head to san francisco!! later.. -Original Message- From: John Nichel [mailto:[EMAIL PROTECTED] Sent: Friday, September 16, 2005 10:19 AM To: php-general@lists.php.net Subject: Re: [PHP] email validation regex Jordan Miller wrote: > What do you mean? What's wrong with top posting? ;) The bait is on the hook.. -- John C. Nichel ÜberGeek KegWorks.com 716.856.9675 [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] email validation regex
Jordan Miller wrote: What do you mean? What's wrong with top posting? ;) The bait is on the hook.. -- John C. Nichel ÜberGeek KegWorks.com 716.856.9675 [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] email validation regex
What do you mean? What's wrong with top posting? ;) Jordan On Sep 16, 2005, at 11:31 AM, John Nichel wrote: bruce wrote: hi.. looking for a good/working/tested php email validation regex that conforms to the rfc2822 standard. a lot of what i've seen from google breaks, or doesn't follow the standard! any ideas/thoughts/sample code/etc... Didn't we just have this flame war about a month ago? Is it time for it to come up again? Top posting must be right around the corner; damn, I love this time of year. ;) -- John C. Nichel ÜberGeek KegWorks.com 716.856.9675 [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] email validation regex
bruce wrote: hi.. looking for a good/working/tested php email validation regex that conforms to the rfc2822 standard. a lot of what i've seen from google breaks, or doesn't follow the standard! any ideas/thoughts/sample code/etc... Didn't we just have this flame war about a month ago? Is it time for it to come up again? Top posting must be right around the corner; damn, I love this time of year. ;) -- John C. Nichel ÜberGeek KegWorks.com 716.856.9675 [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] email validation regex
bruce wrote: hi.. looking for a good/working/tested php email validation regex that conforms to the rfc2822 standard. a lot of what i've seen from google breaks, or doesn't follow the standard! any ideas/thoughts/sample code/etc... I use this code to build the regex $tld='[a-z]{2,}'; $regexp='^([_a-z0-9-]+)(\.[_a-z0-9-]+)*'. '@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.'.$tld.')$'; And test it like this: /* BEGIN PHP code*/ if (eregi($regexp, $email)) { list($username,$domaintld) = split("@",$email); // Validate domain if (getmxrr($domaintld,$mxrecords)) { $valid = true; /*print("Domain: $domaintld"); foreach($mxrecords as $mxKey => $mxValue) print(" $mxValue");*/ } else { if (checkdnsrr($domaintld, "any")) $valid=true; else $errors.="The domain ('$domaintld') is invalid.". " Please check the email."; } } else { $errors.="The email ('$email') isn't valid."; $valid = false; } /* END PHP code*/ I used to get TLD list from http://data.iana.org/TLD/tlds-alpha-by-domain.txt Replacing the above TLD with /*$tld = '(AC|AD|AE|AERO|AF|AG|AI|AL|AM|AN|AO|AQ|AR|ARPA|AS|AT|AU|AW|AZ|'. 'BA|BB|BD|BE|BF|BG|BH|BI|BIZ|BJ|BM|BN|BO|BR|BS|BT|BV|BW|BY|BZ|CA|CC|'. 'CD|CF|CG|CH|CI|CK|CL|CM|CN|CO|COM|COOP|CR|CU|CV|CX|CY|CZ|DE|DJ|DK|DM'. '|DO|DZ|EC|EDU|EE|EG|ER|ES|ET|EU|FI|FJ|FK|FM|FO|FR|GA|GB|GD|GE|GF|GG|GH|'. 'GI|GL|GM|GN|GOV|GP|GQ|GR|GS|GT|GU|GW|GY|HK|HM|HN|HR|HT|HU|ID|IE|IL|'. 'IM|IN|INFO|INT|IO|IQ|IR|IS|IT|JE|JM|JO|JP|KE|KG|KH|KI|KM|KN|KR|KW|KY'. '|KZ|LA|LB|LC|LI|LK|LR|LS|LT|LU|LV|LY|MA|MC|MD|MG|MH|MIL|MK|ML|MM|MN|'. 'MO|MP|MQ|MR|MS|MT|MU|MUSEUM|MV|MW|MX|MY|MZ|NA|NAME|NC|NE|NET|NF|NG|'. 'NI|NL|NO|NP|NR|NU|NZ|OM|ORG|PA|PE|PF|PG|PH|PK|PL|PM|PN|PR|PRO|PS|PT|'. 'PW|PY|QA|RE|RO|RU|RW|SA|SB|SC|SD|SE|SG|SH|SI|SJ|SK|SL|SM|SN|SO|SR|ST'. '|SU|SV|SY|SZ|TC|TD|TF|TG|TH|TJ|TK|TL|TM|TN|TO|TP|TR|TT|TV|TW|TZ|UA|'. 'UG|UK|UM|US|UY|UZ|VA|VC|VE|VG|VI|VN|VU|WF|WS|YE|YT|YU|ZA|ZM|ZW)'; */ But as I check if the email domain part is exists, this is not needed. This is fairly good, and is adapted from a page that i don't have here the reference. I think that it is RFC compatible in the regex, cause I remember to see it to build the regex. The domain check code is adapted as the in the original code it only checks for MX records, but in the RFC says that if no MX records exist (where he should deliver), try to deliver to the machine, e.g., if no mail.isp.com MX records exist, try to deliver the message to the mail.isp.com machine (with SMTP, obviously). PS: your Perl solution can be good, but I think that there exist PHP classes that do it, but I don't know one. -- Nuno Pereira -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] email validation regex
perl has a mod "email::valid" that claims to do email validation, and it appears to be fairly complex/lengthy. i'm considering simply using this in a perl app, that i'd then call from the php function... use the best tool for the job in the quickest manner!!! thoughts -bruce -Original Message- From: Kevin Waterson [mailto:[EMAIL PROTECTED] Sent: Friday, September 16, 2005 8:08 AM To: php-general@lists.php.net Subject: Re: [PHP] email validation regex This one time, at band camp, "bruce" <[EMAIL PROTECTED]> wrote: > hi.. > > looking for a good/working/tested php email validation regex that conforms > to the rfc2822 standard. This will be fun, everybody has their own which is always best. No two people will agree what is correct method and will always come with a 'better' one. This is generally accompanied by derision and ridicule of the others. To this end, I will start the ball rolling with this one... preg_match('/[EMAIL PROTECTED],}\.[\w]{2,6}$/iU', $email) Kevin -- "Democracy is two wolves and a lamb voting on what to have for lunch. Liberty is a well-armed lamb contesting the vote." -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] email validation regex
This one time, at band camp, "bruce" <[EMAIL PROTECTED]> wrote: > hi.. > > looking for a good/working/tested php email validation regex that conforms > to the rfc2822 standard. This will be fun, everybody has their own which is always best. No two people will agree what is correct method and will always come with a 'better' one. This is generally accompanied by derision and ridicule of the others. To this end, I will start the ball rolling with this one... preg_match('/[EMAIL PROTECTED],}\.[\w]{2,6}$/iU', $email) Kevin -- "Democracy is two wolves and a lamb voting on what to have for lunch. Liberty is a well-armed lamb contesting the vote." -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php