<html>
<head>
<title>php正则验证email地址-bbs.it-home.org</title>
</head>
<body>
<?php
if
(isset(
$_POST
[
'posted'
])) {
$email
=
$_POST
[
'email'
];
$theresults
=
ereg
(
"^[^@ ]+@[^@ ]+.[^@ .]+$"
,
$email
,
$trashed
);
if
(
$theresults
) {
$isamatch
=
"有效的email地址"
;
}
else
{
$isamatch
=
"无效的email地址"
;
}
echo
"经验证,您输入的Email:是"
.
$isamatch
;
}
?>
<form action=
"<?php echo $_SERVER['PHP_SELF']; ?>"
method=
"POST"
>
<input type=
"hidden"
name=
"posted"
value=
"true"
>
请输入要验证的E-Mail地址:
<input type=
"text"
name=
"email"
value=
"name@example.com"
>
<input type=
"submit"
value=
"Validate"
>
</form>
</body>
</html>