Ok we all have some lil snippets of code we fall back on time-&-time again so I thought would be a nice idea to share some of them out
So I'll start it of......
this is a simple function I cobbled together after reading some tuts on validating email adresses with PHP
It checks email formatting and also that domain exsists - not foolproof but should help weed out things like adflhad@asdfhlsd.com
Code://check email is valid format function emailsyntax_is_valid($email) { $to_work_out = explode("@", $email); if (!isset($to_work_out[0])) return FALSE; if (!isset($to_work_out[1])) return FALSE; $pattern_local = '^([0-9a-z]*([-|_]?[0-9a-z]+)*)(([-|_]?)\.([-|_]?)[0-9a-z]*([-|_]?[0-9a-z]+)+)*([-|_]?)$'; $pattern_domain = '^([0-9a-z]+([-]?[0-9a-z]+)*)(([-]?)\.([-]?)[0-9a-z]*([-]?[0-9a-z]+)+)*\.[a-z]{2,4}$'; $match_local = eregi($pattern_local, $to_work_out[0]); $match_domain = eregi($pattern_domain, $to_work_out[1]); if ($match_local && $match_domain) { list($user, $domain) = split("@", $email, 2); if (! checkdnsrr($domain, "MX")) { return FALSE; } else { return TRUE; } } return FALSE; }