使用preg_match也接受@

时间:2015-03-25 16:32:13

标签: php preg-match

度过了一段艰难的时光......对于你来说,NINJA应该很容易。

以下是我的功能的一部分:

  if (strlen($_POST['uname']) < 3 || strlen($_POST['uname']) > 30 || !preg_match("/^([0-9A-Za-z])+$/i", $_POST['uname']) || $uname != 2)

我们也希望包含电子邮件地址,但无法弄清楚如何包含&#34; @&#34;符号呢?

提前谢谢!!

1 个答案:

答案 0 :(得分:2)

如果我理解你想要的东西:!preg_match(“/ ^([\ W])+ $ / i”或者可能使用posix:

<?php
$regex = '[[:punct:]]';

if (preg_match('/'.$regex.'/', 'somepas$', $matches)) {
    print_r($matches);
}
?>