Re: [PHP] email address syntax checker
> Trying to finish a PHP book while watching the Packers is not working > for me too well. ;-) yeah.. me trying to keep up with the php list, follow streams of thought from the posts that lead to things I need to yet learn, make time off from my other-language/full-time work.. wishing I could actually play Civ-V which I just bought.. .. not to mention my business idea guaranteed to make a mint and be a ton of fun (if I had a year off to code it)... ;-) Govinda -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] email address syntax checker
Govinda wrote: [snip] Hi D :-) I was following along.. also felt pleased to be introduced to filter_var ... and then happened to see this: http://us3.php.net/manual/en/function.filter-var.php [snip] "Note that FILTER_VALIDATE_EMAIL used in isolation is not enough for most (if not all) web based registration forms. Good to know G... (and yea, I read something similar).. but only administrators can add registrants in the system I'm building.. and even then, email is not required, so I'm not worried about it on this job, but I'll keep all the posts for this thread in mind for down the road. Trying to finish a PHP book while watching the Packers is not working for me too well. ;-) Thanks, Donovan -- D Brooke -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] email address syntax checker
On Sun, 2011-01-23 at 14:59 -0500, Govinda wrote: > > Peter Lind wrote: > > [snip] > >> if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { > >> echo "Bad user! Bad user!"; > >> } > >> > >> Regards > >> Peter > > > > > > thanks peter... wish I would have known about filter_var before > > writing the other checkers. ;-) > > > Hi D :-) > > I was following along.. also felt pleased to be introduced to filter_var ... > and then happened to see this: > > http://us3.php.net/manual/en/function.filter-var.php > the user-contributed note, headed with: > php dot 5 dot leenoble at SPAMMENOTspamgourmet dot net 18-Dec-2009 10:01 > > "Note that FILTER_VALIDATE_EMAIL used in isolation is not enough for most (if > not all) web based registration forms. > > It will happily pronounce "yourname" as valid because presumably the > "@localhost" is implied, so you still have to check that the domain portion > of the address exists. > " > > So I am surprised Peter recommended it. (?) > > AFAICT, I should stick with what I was using: > > $emailPattern = '/^[\w\.\-_\+]+@[\w-]+(\.\w{2,4})+$/i'; // > $emailReplacement = 'theEmailAppearsValid'; > $emailChecker = preg_replace($emailPattern, $emailReplacement, $emailToCheck); > if($emailChecker == 'theEmailAppearsValid') { > //--theEmailLooksValid, so use it... > } else { > //--theEmailLooksBad, so do not use it... > } > > > > Govinda > > A few posts back I posted a solution to a question about validating domain names. You could use that to validate the portion after the last '@' symbol (as an @ could validly occur in the local part of the email address) and then validate the front part another way (I can't write all the code for you ;p ) The domain code I used before was: http://www.ashleysheridan.co.uk
Re: [PHP] email address syntax checker
> Peter Lind wrote: > [snip] >> if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { >> echo "Bad user! Bad user!"; >> } >> >> Regards >> Peter > > > thanks peter... wish I would have known about filter_var before > writing the other checkers. ;-) Hi D :-) I was following along.. also felt pleased to be introduced to filter_var ... and then happened to see this: http://us3.php.net/manual/en/function.filter-var.php the user-contributed note, headed with: php dot 5 dot leenoble at SPAMMENOTspamgourmet dot net 18-Dec-2009 10:01 "Note that FILTER_VALIDATE_EMAIL used in isolation is not enough for most (if not all) web based registration forms. It will happily pronounce "yourname" as valid because presumably the "@localhost" is implied, so you still have to check that the domain portion of the address exists. " So I am surprised Peter recommended it. (?) AFAICT, I should stick with what I was using: $emailPattern = '/^[\w\.\-_\+]+@[\w-]+(\.\w{2,4})+$/i'; // $emailReplacement = 'theEmailAppearsValid'; $emailChecker = preg_replace($emailPattern, $emailReplacement, $emailToCheck); if($emailChecker == 'theEmailAppearsValid') { //--theEmailLooksValid, so use it... } else { //--theEmailLooksBad, so do not use it... } Govinda -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] email address syntax checker
On Fri, 21 Jan 2011 18:32:56 +0530, Nilesh Govindarajan wrote: > Okay let me tell you guys one more thing that the validator I posted > earlier is not exactly as per RFC. It does have some variations. > "@"@example.com may be a valid email address, but I doubt very much if > any provider in the universe gives such an address? Sending to, and receiving at <"@"@luden.se> seems to work fine here. /Nisse -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] email address syntax checker
On 01/21/2011 06:25 AM, Andre Polykanine wrote: Hej Nisse, Me thinks it isn't a valid address :-). Okay let me tell you guys one more thing that the validator I posted earlier is not exactly as per RFC. It does have some variations. "@"@example.com may be a valid email address, but I doubt very much if any provider in the universe gives such an address? It has been coded partially according to RFC and partially according to common sense. [[NO FLAMES]] -- Regards, Nilesh Govindarajan Facebook: http://www.facebook.com/nilesh.gr Twitter: http://twitter.com/nileshgr Website: http://www.itech7.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: RES: [PHP] email address syntax checker
On 21 January 2011 11:38, a...@ashleysheridan.co.uk wrote: > That won't accept dozens of different types of email addresses. It won't even > match some value domains. > > Valid email addresses can contain virtually any character in the local part > (although in the main they will require being inside quotation marks), and > the @ symbol is included in that! > > Thanks, > Ash > http://www.ashleysheridan.co.uk > > - Reply message - > From: "Alejandro Michelin Salomon" > Date: Fri, Jan 21, 2011 12:14 > Subject: RES: [PHP] email address syntax checker > To: "'Donovan Brooke'" > Cc: > > > > Donovan: > > Try this > > function EmailCheck ( $sEmail ) > { > > $regexp="/^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z > ]{2,}$/i"; > > if ( !preg_match($regexp, $sEmail) ) > return false; > > return true; > } > > Alejandro M.S. > -Mensagem original- > De: Donovan Brooke [mailto:li...@euca.us] > Enviada em: quinta-feira, 20 de janeiro de 2011 01:14 > Para: php-general@lists.php.net > Assunto: [PHP] email address syntax checker > > Hi Guys, > > I'm waddling my way through database interaction and thought someone on > the list may already have a simple email checker that they'd like to > share... > > you know, looking for the @ char and dots etc.. > > I did a quick search of the archives and found a couple elaborate > things.. but > I'm looking for something simple. This job will have trusted users and > the checker is more to help them catch mistakes when registering. > > Thanks!, > Donovan > > > -- > D Brooke > > -- > 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 > > http://www.regular-expressions.info/email.html makes a good argument about the futility of using JUST one massive regex to validate email addresses. The long and short of it is the standard says that this should work ... (?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\]) Which is ... (?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\]) Which (using RegexBuddy) is explained as ... Options: case insensitive; ^ and $ match at line breaks Match the regular expression below «(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")» Match either the regular expression below (attempting the next alternative only if this one fails) «[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*» Match a single character present in the list below «[a-z0-9!#$%&'*+/=?^_`{|}~-]+» Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+» A character in the range between “a” and “z” «a-z» A character in the range between “0” and “9” «0-9» One of the characters “!#$%&'*+/=?^_`{|}” «!#$%&'*+/=?^_`{|}» The character “~” «~» The character “-” «-» Match the regular expression below «(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*» Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*» Match the character “.” literally «\.» Match a single character present in the list below «[a-z0-9!#$%&'*+/=?^_`{|}~-]+» Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+» A character in the range between “a” and “z” «a-z» A character in the range between “0” and “9” «0-9» One of the characters “!#$%&'*+/=?^_`{|}” «!#$%&'*+/=?^_`{|}» The character “~” «~» The character “-” «-» Or match regular expression
Re: RES: [PHP] email address syntax checker
That won't accept dozens of different types of email addresses. It won't even match some value domains. Valid email addresses can contain virtually any character in the local part (although in the main they will require being inside quotation marks), and the @ symbol is included in that! Thanks, Ash http://www.ashleysheridan.co.uk - Reply message - From: "Alejandro Michelin Salomon" Date: Fri, Jan 21, 2011 12:14 Subject: RES: [PHP] email address syntax checker To: "'Donovan Brooke'" Cc: Donovan: Try this function EmailCheck ( $sEmail ) { $regexp="/^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z ]{2,}$/i"; if ( !preg_match($regexp, $sEmail) ) return false; return true; } Alejandro M.S. -Mensagem original- De: Donovan Brooke [mailto:li...@euca.us] Enviada em: quinta-feira, 20 de janeiro de 2011 01:14 Para: php-general@lists.php.net Assunto: [PHP] email address syntax checker Hi Guys, I'm waddling my way through database interaction and thought someone on the list may already have a simple email checker that they'd like to share... you know, looking for the @ char and dots etc.. I did a quick search of the archives and found a couple elaborate things.. but I'm looking for something simple. This job will have trusted users and the checker is more to help them catch mistakes when registering. Thanks!, Donovan -- D Brooke -- 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
RES: [PHP] email address syntax checker
Donovan: Try this function EmailCheck ( $sEmail ) { $regexp="/^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z ]{2,}$/i"; if ( !preg_match($regexp, $sEmail) ) return false; return true; } Alejandro M.S. -Mensagem original- De: Donovan Brooke [mailto:li...@euca.us] Enviada em: quinta-feira, 20 de janeiro de 2011 01:14 Para: php-general@lists.php.net Assunto: [PHP] email address syntax checker Hi Guys, I'm waddling my way through database interaction and thought someone on the list may already have a simple email checker that they'd like to share... you know, looking for the @ char and dots etc.. I did a quick search of the archives and found a couple elaborate things.. but I'm looking for something simple. This job will have trusted users and the checker is more to help them catch mistakes when registering. Thanks!, Donovan -- D Brooke -- 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 address syntax checker
Hej Nisse, Me thinks it isn't a valid address :-). -- With best regards from Ukraine, Andre Skype: Francophile My blog: http://oire.org/menelion (mostly in Russian) Twitter: http://twitter.com/m_elensule Facebook: http://facebook.com/menelion Original message From: Nisse Engström To: php-general@lists.php.net Date created: , 2:25:01 AM Subject: [PHP] email address syntax checker On Thu, 20 Jan 2011 19:03:22 +0530, Nilesh Govindarajan wrote: > Well, I had created an email validator long ago, after a neat research > on Google, reading RFCs, etc. > I don't guarantee that it's without bugs, but it has been correct for me > in all valid & invalid email addresses I used for test. > > Code: > > > function checkMail($mail) { > >if(strlen($mail) <= 0) { > return false; >} > >$split = explode('@', $mail); > >if(count($split) > 2) { > return false; >} <"@"@example.com> is not a valid address? /Nisse -- 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 address syntax checker
On Thu, 20 Jan 2011 19:03:22 +0530, Nilesh Govindarajan wrote: > Well, I had created an email validator long ago, after a neat research > on Google, reading RFCs, etc. > I don't guarantee that it's without bugs, but it has been correct for me > in all valid & invalid email addresses I used for test. > > Code: > > > function checkMail($mail) { > >if(strlen($mail) <= 0) { > return false; >} > >$split = explode('@', $mail); > >if(count($split) > 2) { > return false; >} <"@"@example.com> is not a valid address? /Nisse -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] email address syntax checker
Nilesh Govindarajan wrote: On 01/20/2011 09:44 AM, Donovan Brooke wrote: Hi Guys, I'm waddling my way through database interaction and thought someone on the list may already have a simple email checker that they'd like to share... you know, looking for the @ char and dots etc.. I did a quick search of the archives and found a couple elaborate things.. but I'm looking for something simple. This job will have trusted users and the checker is more to help them catch mistakes when registering. Thanks!, Donovan Well, I had created an email validator long ago, after a neat research on Google, reading RFCs, etc. I don't guarantee that it's without bugs, but it has been correct for me in all valid & invalid email addresses I used for test. Code: 2) { return false; } list($username, $domain) = $split; /* * Don't allow * Two dots, Two @ * !, #, $, ^, &, *, (, ), [, ], {, }, ?, /, \, ~, `, <, >, ', " */ $userNameRegex1 = '/\.{2,}|@{2,}|[\!#\$\^&\*\(\)\[\]{}\?\/\\\|~`<>\'"]+/'; /* * Username should consist of only * A-Z, a-z, 0-9, -, ., _, +, % */ $userNameRegex2 = '/[a-z0-9_.+%-]+/i'; /* * Domain cannot contain two successive dots */ $domainRegex1 = '/\.{2,}/'; /* * Domain can contain only * A-Z, a-z, 0-9, ., -, */ $domainRegex2 = '/[a-z0-9.-]+/i'; if(preg_match($userNameRegex1, $username) or !preg_match($userNameRegex2, $username) or preg_match($domainRegex1, $domain) or !preg_match($domainRegex2, $domain) or !checkdnsrr($domain, 'MX')) { return false; } else { return true; } } Thanks! I think I'll go w/ Peter's suggestion for this site, but will take note of this for reference's sake! Cheers, Donovan -- D Brooke -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] email address syntax checker
Peter Lind wrote: [snip] if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { echo "Bad user! Bad user!"; } Regards Peter thanks peter... wish I would have known about filter_var before writing the other checkers. ;-) Donovan -- D Brooke -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] email address syntax checker
On 01/20/2011 09:44 AM, Donovan Brooke wrote: Hi Guys, I'm waddling my way through database interaction and thought someone on the list may already have a simple email checker that they'd like to share... you know, looking for the @ char and dots etc.. I did a quick search of the archives and found a couple elaborate things.. but I'm looking for something simple. This job will have trusted users and the checker is more to help them catch mistakes when registering. Thanks!, Donovan Well, I had created an email validator long ago, after a neat research on Google, reading RFCs, etc. I don't guarantee that it's without bugs, but it has been correct for me in all valid & invalid email addresses I used for test. Code: 2) { return false; } list($username, $domain) = $split; /* * Don't allow * Two dots, Two @ * !, #, $, ^, &, *, (, ), [, ], {, }, ?, /, \, ~, `, <, >, ', " */ $userNameRegex1 = '/\.{2,}|@{2,}|[\!#\$\^&\*\(\)\[\]{}\?\/\\\|~`<>\'"]+/'; /* * Username should consist of only * A-Z, a-z, 0-9, -, ., _, +, % */ $userNameRegex2 = '/[a-z0-9_.+%-]+/i'; /* * Domain cannot contain two successive dots */ $domainRegex1 = '/\.{2,}/'; /* * Domain can contain only * A-Z, a-z, 0-9, ., -, */ $domainRegex2 = '/[a-z0-9.-]+/i'; if(preg_match($userNameRegex1, $username) or !preg_match($userNameRegex2, $username) or preg_match($domainRegex1, $domain) or !preg_match($domainRegex2, $domain) or !checkdnsrr($domain, 'MX')) { return false; } else { return true; } } -- Regards, Nilesh Govindarajan Facebook: http://www.facebook.com/nilesh.gr Twitter: http://twitter.com/nileshgr Website: http://www.itech7.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] email address syntax checker
On 20 January 2011 05:14, Donovan Brooke wrote: > Hi Guys, > > I'm waddling my way through database interaction and thought someone on the > list may already have a simple email checker that they'd like to share... > > you know, looking for the @ char and dots etc.. > > I did a quick search of the archives and found a couple elaborate things.. > but > I'm looking for something simple. This job will have trusted users and > the checker is more to help them catch mistakes when registering. if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { echo "Bad user! Bad user!"; } Regards Peter -- WWW: plphp.dk / plind.dk LinkedIn: plind BeWelcome/Couchsurfing: Fake51 Twitter: kafe15 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] email address syntax checker
On Wed, Jan 19, 2011 at 11:14 PM, Donovan Brooke wrote: > Hi Guys, > > I'm waddling my way through database interaction and thought someone on the > list may already have a simple email checker that they'd like to share... > > you know, looking for the @ char and dots etc.. > > I did a quick search of the archives and found a couple elaborate things.. > but > I'm looking for something simple. Simple is an irrelevant term, you'd have to elaborate on your current experience. This job will have trusted users and > the checker is more to help them catch mistakes when registering. > > Thanks!, > Donovan > > > -- > D Brooke > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- The lawyer in me says argue...even if you're wrong. The scientist in me... says shut up, listen, and then argue. But the lawyer won on appeal, so now I have to argue due to a court order. Furthermore, if you could be a scientific celebrity, would you want einstein sitting around with you on saturday morning, while you're sitting in your undies, watching Underdog?...Or better yet, would Einstein want you to violate his Underdog time? Can you imagine Einstein sitting around in his underware? Thinking about the relativity between his cotton nardsac, and his Fruit of the Looms? But then again, J. Edgar Hoover would want his pantyhose intertwined within the equation. However, I digress, momentarily. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] email address syntax checker
Hi Guys, I'm waddling my way through database interaction and thought someone on the list may already have a simple email checker that they'd like to share... you know, looking for the @ char and dots etc.. I did a quick search of the archives and found a couple elaborate things.. but I'm looking for something simple. This job will have trusted users and the checker is more to help them catch mistakes when registering. Thanks!, Donovan -- D Brooke -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php