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

实例

<?php

php邮箱正则匹配PHP 邮箱正则表达式 Bootstrap

$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); //输出匹配结果

?&gt;

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

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;