<html>
<head>
<title>向函数传递表单数据</title>
</head>
<body>
<form action="index.php" method="post"> <!-- index.php,和文件同名 -->
<input type="text" name="email" size="20" maxlength="40" value="">
<br/>
<input type="submit" name="submit" value="检测email的合法性">
</form>
</body>
</html>
<?php
function Authentication($email)
{
$regexp = "^([_a-z0-9-]+)(\.[_a-z0-9]+)*@([a-z0-9]+)(\.[a-z0-9-]+)*(\.[a-z]{2,6})$";
if(eregi($regexp,$email))
{
return true;
}
else
{
return false;
}
}
if(isset($_POST['submit']))
{
if(Authentication($_POST['email']))
{
echo $_POST['email']."合法";
}
else
{
echo $_POST['email']."不合法";
}
}
?>