多个preg_match查询?

时间:2016-12-10 21:44:42

标签: php regex preg-match

我是php的新手并尝试编写验证我的表单的代码。现在问题是我在这行代码中遇到了麻烦:

$fullname_pattern = "/[a-zA-Z]+/";
$fullname = $_POST['fullname'];

$email = $_POST['email'];
$email_pattern = "/^[a-zA-Z]+([a-zA-Z0-9]+)?@[a-zA-Z]{3,50}\.(com|net|org)/";

$password = $_POST['password'];
$password_pattern = "/(.){6,12}/";


if(preg_match($fullname_pattern,$fullname)) && 
      (preg_match($email_pattern,$email)) && 
      (preg_match($password_pattern,$password)) 
        {             
            header("Location: home.php");
        }
     else
            header("Location: registration.php");

不知道该怎么做!

1 个答案:

答案 0 :(得分:0)

if(preg_match($fullname_pattern,$fullname)) 删除最后")"

并在此处添加(preg_match($password_pattern,$password)))

像这样:

if(preg_match($fullname_pattern,$fullname) && preg_match($email_pattern,$email) && preg_match($password_pattern,$password) ) {

相关问题