Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

is_valid_email_address function (See related posts)

// description of your code here


/* Regex for validating email address */
function is_valid_email_address($email_address)
{
  if (ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,6})$",$email_address) )
  {
    return TRUE;
  }
  else
  {
    return FALSE;
  }
}


Comments on this post

nickstenning posts on Jan 04, 2007 at 09:54
No no no no no no no!!!

I know it's an easy mistake, but it absolutely *infuriates* me when people arbitrarily decide what a valid email address is. By your reckoning, neither of the following are valid email addresses, when in fact every single one of them is just fine.

[email protected]
[email protected]

If you *really* need to validate email addresses, use a *proper* regex, like that found at http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html, but chances are you just want to double check that the user input is sensible -- in that case give them two boxes, and just check that it's of the form (stuff)@(stuffwithatleastonedot)

Don't do any more than that or you run into all sorts of stupid problems.
nickstenning posts on Jan 04, 2007 at 09:55
s/every single one/both/

You need to create an account or log in to post comments to this site.


Related Posts