function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
$name = test_input($_POST["name"]);
if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
$nameErr = "只允许字母和空格!";
}
$email = test_input($_POST["email"]);
if (!preg_match("/([w-]+@[w-]+.[w-]+)/",$email)) {
$emailErr = "无效的 email 格式!";
}
$website = test_input($_POST["website"]);
if (!preg_match("/(?:(?:https?|ftp)://|www.)[-a-z0-9+&@#/%?=~_|!:,.;]*[-a-z0-9+&@#/%
=~_|]/i",$website)) {
$websiteErr = "无效的 URL";
}