简体   繁体   English

验证,我在做什么错?

[英]validation, what am i doing wrong?

So basiclly i just want this code below: 所以基本上我只想要下面的代码:

    //basic email validation
    if(!eregi('^x[\d]{8}@student\.ncirl\.ie$', $email)){
        // Return Error - Invalid Email
        $error = true;
        $emailError = 'The email you have entered is invalid, please try again.';
    }
    if ( !filter_var($email,FILTER_VALIDATE_EMAIL) ) {
        $error = true;
        $emailError = "Please enter valid email address.";
    } else {
        // check email exist or not
        $query = "SELECT userEmail FROM users WHERE userEmail='$email'";
        $result = mysql_query($query);
        $count = mysql_num_rows($result);
        if($count!=0){
            $error = true;
            $emailError = "Provided Email is already in use.";
        }
    }

To validate the email if it is exactly similar to email - "x14332684@student.ncirl.ie" , i want it to keep the x at the start, have 8 random numbers after x and as it is everything after @. 要验证电子邮件是否与电子邮件完全相似-“ x14332684@student.ncirl.ie”,我希望它以x开头,在x之后有8个随机数,因为@之后是所有数字。 Only numbers to be random and the rest should be a "must". 只有数字是随机的,其余的应该是“必须”。 I just cant get it to validate the email like i want, using this code tells me pernament "The email you have entered is invalid, please try again.". 我只是无法像我想要的那样来验证电子邮件,使用此代码可以告诉我“您输入的电子邮件无效,请重试。”。 Can anyone edit the code for me and point out what am i doing wrong in it? 谁能为我编辑代码并指出我在其中做错了吗? Thank you. 谢谢。

This works with preg_match. 这适用于preg_match。 One thing you need to do is wrap the pattern with delimiters, most use / like: 您需要做的一件事是用定界符将模式包装起来,大多数使用/

if(!preg_match('/^x[\d]{8}@student\.ncirl\.ie$/', $email)){
    // Return Error - Invalid Email
    $error = true;
    $emailError = 'The email you have entered is invalid, please try again.';
}

http://php.net/manual/en/function.preg-match.php http://php.net/manual/zh/function.preg-match.php

使用此站点: http : //www.phpliveregex.com/以获取将来的preg_matche

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM