Forum Moderators: coopster

Message Too Old, No Replies

Verifying that an email ends in "@example.com"

For when users register

         

Vastio

7:19 pm on Mar 7, 2006 (gmt 0)

10+ Year Member



Hi,

When users register for my site, I'd like to be able to limit which domain their email address can be from, so that only people with "...@example.com" addresses can sign up. It would kind of be the opposite of how WW checks to make sure your email isn't from a free webmail site.

The one idea I had was to do a string reverse (turn it into "moc.elpmaxe@...") then verify the first 11 characters to see if they match with the approved domain range.

Is there a better way of doing this or am I on the right track?
Thanks

pinterface

7:34 pm on Mar 7, 2006 (gmt 0)

10+ Year Member



There's no need to reverse the string.

[url=http://us2.php.net/manual/en/function.preg-match.php]preg_match[/url]('/@example\\.com$/', $email)
or
[url=http://us2.php.net/manual/en/function.strrchr.php]strrchr[/url]($email, '@') == '@example.com'
should work just fine.