Code:
<?php
function checkEmail($email) {
$emailParts = explode("@", $email);
$beforeAtSymbol = $emailParts[0];
if (substr_count($emailParts[1], ".") > 2) {
//Too many dots after the @ symbol.
return false;
}
$afterAtSymbol = explode(".", $emailParts[1]);
if ($beforeAtSymbol == "") {
return false;
}
if (sizeof($emailParts) !== 2) {
//You need one and only one @ in the email.
return false;
}
if (strlen($beforeAtSymbol) < 2 || strlen($beforeAtSymbol) > 30) {
//I do not know anybody who has an e-mail that is longer than 30 characters for what is before the @ symbol, or who has an e-mail with only one letter there.
return false;
}
for ($i = 0; $i < sizeof($afterAtSymbol); $i++) {
}
if (sizeof($afterAtSymbol) > 3 || sizeof($afterAtSymbol) == 0) {
return false;
}
if (strlen($afterAtSymbol[0]) > 20 || strlen($afterAtSymbol[0]) < 2) {
return false;
}
if (strlen($afterAtSymbol[1]) > 4 || strlen($afterAtSymbol[2]) > 4) {
//.com, .info, .biz, .us....none of these are more than 4 characters.
return false;
}
return true;
}
?>
E-mail check function. It's certainly not bulletproof, but it's acceptable. Returns false or true. Most of your validations shouldn't be hard....just make sure the name is between 0 and 30 characters, etc.
I will post a phone number validator if I can find it in my files...