There are several ways, generally involving regular expressions (POSIX std.) or PCRE's (PERL-Compatible regular expressions.) Here's a function I used some time ago, [man]using ereg/man (POSIX). Feed it the variable and a string that represents the data type, English names, email addy, or US phone number...
function ValidateInput($var, $type) {
trim($var);
if ($type=="name") { $Pattern = "^[A-Z][c]?[A-Z]?[a-z]+[a-z]$"; }
elseif ($type=="email") { $Pattern = "^([0-9a-z]+)([0-9a-z\._-]+)@([0-9a-z\._-]+)\.([0-9a-z]+)"; }
elseif ($type=="phone") { $Pattern = "^([0-9]{3})-([0-9]{4})-([0-9]{4})"; }
$valid=ereg($Pattern, $var);
return $valid;
} # end of Function
Call it thus:
$valid=ValidateInput($email, "email");
if (!$valid) { echo "You email address sux!"; }
😉
As I said, this is just one way, and a little more than you asked for, but it worx....
HAND,