PHP正则验证邮箱类

代码
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>验证邮箱的正则表达式</title>
</head>
<body>
<form action="lession6.php" method="post">
<table align="center">
<tr>
<td>邮箱:<input type="text" name="mail"></td>
<td><input type="submit" value="确认" style="width:35px;height:17px;"></td>
</tr>
</table>
</form>
</body>
</html>

 

代码
1 <?php
2 class Reg{
3 public $mail;
4 function __construct(){
5 $this->mail = $_POST["mail"];
6
7 }
8 function RegMail(){
9 if(preg_match("/^[0-9a-zA-Z]+(?:[\_\-][a-z0-9\-]+)*@[a-zA-Z0-9]+(?:[-.][a-zA-Z0-9]+)*\.[a-zA-Z]+$/i", $this->mail)){
10 echo "<script language='javascript'>alert('验证成功')</script>";
11 }else{
12 echo "<script language='javascript'>alert('验证失败')</script>";
13 }
14 }
15 }
16 $r = new Reg();
17 $r->RegMail();
18  ?>

 

posted on 2011-01-06 12:00  funkys  阅读(1569)  评论(0)    收藏  举报