RE: [PHP] More Email ereg Validation

From: Date: Thu, 05 Apr 2001 16:46:23 +0000
Subject: RE: [PHP] More Email ereg Validation
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-47283@lists.php.net to get a copy of this message
> Sorry, but that doesn't work. I thought it would, but it only does two > characters on the top level domain again. Tested at > http://www.php.comzept.de/rexpr (thanks Jörg!) > > Does anyone else (a regex guru) have any other suggestions? The most recent regex you had: ([a-z0-9_\.\-]+)@([a-z0-9\.-]+).([a-z]{2,3}) would still allow addresses such as ____@---.au or _.-._.@.-.com. (Actually, with the . there, you could even have _.-._.@.-|com) Regardless, here's a regex I've adjusted to try and keep the address as close to good form as possible: "^[0-9a-z]+([-_./]([0-9a-z]+))*@[0-9a-z]+([-.]([0-9a-z]+))*\\.[a-z]{2,4}$" A little longer, but it does the trick (I've tried hitting it with a bunch of possibilities, but I may have missed some. <G>) We have some lists that contain (valid) email addresses like joe/loc@fs.fed.us, so I've allowed a / as a separator to the left of the @. (If you don't want to allow this, just replace [-_./] with [-_.] and it'll be gone. At the end of the regex, I allow 2-3 characters but this may need to be 2-5 shortly since the new TLDs may start coming into use. Up to you. Make sure you use eregi instead of just ereg, or lowercase the email address before you check it. We also go a step further and use checkdnsrr to see if there are any (type ANY that is) records available for the hostname part. Not great, but it at least tries to see if the hostname exists. Let me know if it works out for you. Jaime Bozza GeoComm International Corp.

« previous php.general (#47283) next »