本文介绍下,在php中借助正则表达式来验证Email邮箱地址的例子,有需要的朋友参考下。
php实现验证邮箱地址的例子,很好的应用了php的正则。
1,html部分
php正则验证Email地址
2,php代码部分 RegularExpressionTester.php
string:$string";
echo " regular expression: $pattern";
if (get_magic_quotes_gpc()){
echo "
";
echo " Stripping magic quotes....";
$string = stripslashes($string);
$pattern = stripslashes($pattern);
echo " string: $string";
echo " regular expression: $pattern";
}
$found = ereg($pattern, $string, $matches);
echo "
";
if ($found)
{
echo " 验证: 成功";
echo "
";
echo " Components: ";
for ($i = 0; $i < count($matches); $i++)
{
echo " $matches[$i]";
}
}
else
echo " 验证: 失败";
?> |