RE: [PHP] What's a good regex to validate an email address? ;)

From: Date: Fri, 17 Oct 2003 19:30:22 +0000
Subject: RE: [PHP] What's a good regex to validate an email address? ;)
Groups: php.general 
Request: Send a blank email to php-general+get-166533@lists.php.net to get a copy of this message
[A-Za-z0-9\_]+\@[A-Za-z][A-Za-z0-9]+\.(net|com|org|gov|...) or [A-Za-z0-9\_]+\@[A-Za-z][A-Za-z0-9]+\.[A-Za-z]+ Will get nearly everything that resembles an email address. Fw9f82e@823ngfj27.eoe would even go through the second one. Best thing to do maybe is try to send a email to the address to verify it. > -----Original Message----- > From: Daevid Vincent [mailto:daevid@daevid.com] > Sent: Thursday, October 16, 2003 9:19 PM > To: php-general@lists.php.net > Subject: [PHP] What's a good regex to validate an email address? ;) > > Not PHP, but in js, I use this: > > function emailCheck(str) { > var at="@" > var dot="." > var lat=str.indexOf(at) > var lstr=str.length > var ldot=str.indexOf(dot) > if (str.indexOf(at)==-1){ > return false > } > > if (str.indexOf(at)==-1 || str.indexOf(at)==0 || > str.indexOf(at)==lstr){ > return false > } > > if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || > str.indexOf(dot)==lstr){ > return false > } > > if (str.indexOf(at,(lat+1))!=-1){ > return false > } > > if (str.substring(lat-1,lat)==dot || > str.substring(lat+1,lat+2)==dot){ > return false > } > > if (str.indexOf(dot,(lat+2))==-1){ > return false > } > > if (str.indexOf(" ")!=-1){ > return false > } > > return true > } > > Daevid Vincent > http://daevid.com > > > > -----Original Message----- > > From: John W. Holmes [mailto:holmes072000@charter.net] > > Sent: Wednesday, October 15, 2003 9:29 PM > > To: php list > > Subject: [PHP] What's a good regex to validate an email address? ;) > > > > Heh... I was adding a note to the PHP Manual and I thought it > > was really > > funny they had to include this note in the "rules": > > > > (And if you're posting an example of validating email addresses, > > please don't bother. Your example is almost certainly wrong for some > > small subset of cases. See this information from O'Reilly Mastering > > Regular Expressions book for the gory details.) > > > > lol... > > > > The link is http://examples.oreilly.com/regex/readme.html > > in > > case anyone > > is interested... > > > > -- > > ---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

« previous php.general (#166533) next »