/* 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; } }
2827 users tagging and storing useful source code snippets
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!)
/* 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; } }
You need to create an account or log in to post comments to this site.
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]
nà[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.