簡體   English   中英

驗證,我在做什么錯?

[英]validation, what am i doing wrong?

所以基本上我只想要下面的代碼:

    //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.";
        }
    }

要驗證電子郵件是否與電子郵件完全相似-“ x14332684@student.ncirl.ie”,我希望它以x開頭,在x之后有8個隨機數,因為@之后是所有數字。 只有數字是隨機的,其余的應該是“必須”。 我只是無法像我想要的那樣來驗證電子郵件,使用此代碼可以告訴我“您輸入的電子郵件無效,請重試。”。 誰能為我編輯代碼並指出我在其中做錯了嗎? 謝謝。

這適用於preg_match。 您需要做的一件事是用定界符將模式包裝起來,大多數使用/

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/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