Skip to content

Instantly share code, notes, and snippets.

@MilkZoft
Created January 18, 2012 04:21
Show Gist options
  • Select an option

  • Save MilkZoft/1630952 to your computer and use it in GitHub Desktop.

Select an option

Save MilkZoft/1630952 to your computer and use it in GitHub Desktop.
codejobs - Validate an email - PHP
<?php
function isEmail($email) {
if((strlen($email) >= 6) and (substr_count($email, "@") === 1) and (substr($email, 0, 1) !== "@") and (substr($email, strlen($email) - 1, 1) !== "@")) {
if((!strstr($email, "'")) and (!strstr($email, "\"")) and (!strstr($email, "\\")) and (!strstr($email, "\$")) and (!strstr($email, " "))) {
if(substr_count($email, ".") >= 1) {
$domain = substr(strrchr($email, "."), 1);
if(strlen($domain) > 1 and strlen($domain) < 5 and (!strstr($domain, "@"))) {
$prev = substr($email, 0, strlen($email) - strlen($domain) - 1);
$last = substr($prev, strlen($prev) - 1, 1);
if($last !== "@" and $last !== ".") {
return TRUE;
}
}
}
}
}
return FALSE;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment