/^[_a-z0-9-]+(\.[_a-z0-9-]+)@[a-z0-9-]+(\.[a-z0-9-]+)(\.[a-z]{2,})$/

实例

<?php

php手机号正则表达式PHP 邮箱正则表达式 HTML

$mail = 'runoob@runoob.com'; //邮箱地址

$pattern = \"大众/^[_a-z0-9-]+(\.[_a-z0-9-]+)@[a-z0-9-]+(\.[a-z0-9-]+)(\.[a-z]{2,})$/\"大众;

preg_match($pattern, $mail, $matches);

var_dump($matches); //输出匹配结果

?>

以上代码运行输出结果为:

array(4) {

[0]=>

string(17) \"大众runoob@runoob.com\公众

[1]=>

string(0) \"大众\公众

[2]=>

string(0) \"大众\"大众

[3]=>

string(4) \公众.com\"大众

}

利用 FILTER_VALIDATE_EMAIL 过滤器

实例

<?php

$email = 'runoob@runoob.com'; //邮箱地址

if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {

$emailMsg = \"大众造孽邮箱格式\公众;

} else {

$emailMsg = \"大众精确邮箱格式\"大众;

}

echo $emailMsg;