Welcome, guest | Sign In | My Account | Store | Cart

This is a function i used in order to check if an email submitted by the user is in the proper email format. (does not check if the email exists though). If the email has proper format, will return true, otherwise will return false.

PHP, 7 lines
function CheckEmail($Email = "") {
  if (ereg("[[:alnum:]]+@[[:alnum:]]+\.[[:alnum:]]+", $Email)) {
    return true;
  } else {
    return false;

I think that this would be a good way to make sure that an user did entered a valid email address in an email field for customer registration or something of that kind. I am working on a version that will detect if the email is existant or not.


Olivier Dagenais 21 years, 3 months ago  # | flag

Not quite adequate. It seems the regular expression checks for one or more alphanumerics, an "at", one or more alphanumerics, a "dot" and one or more alphanumerics.

What if my e-mail address has dashes or dots in the user name? What if it's not with a top-level domain name?

Examples that would be rejected:




Just to be really picky, "@ @"@nmt.edu is also a valid e-mail address:


Using info from RFC 1869 http://www.ietf.org/rfc/rfc1869.txt , it should be possible to do hold a conversation with the mail server similar to that shown at: http://www.spamdeputy.com/sa/vrfyemail.htm

Actually, I just found a small PHP snippet that does just that at: http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=612&lngWId=8

...but you probably already knew that, because you left a comment on the message board... :)

Aivar Hiienurm 21 years, 1 month ago  # | flag

LOGICS. there is logics error on this validation, as described on comment abowe, you need to redesign that script

you have to validate by different parts, anyway this not save your @ wrong addresses. anyway, sometimes really usefull.. :)

Created by Steve Belanger on Sat, 20 Apr 2002 (MIT)
PHP recipes (51)
Steve Belanger's recipes (1)

Required Modules

  • (none specified)

Other Information and Tasks