duankan6894 2014-01-24 22:30
浏览 66
已采纳

preg_match使用变量?

here is what i want to try to do. I want an easy way to just add in new emails without having to have my client to have to touch the main code.

$list= 'gmail|yahoo|aol'; 


$banned = '\b[\w\.-]+@((?!'.$list.').)[\w\.-]+\.\w{2,4}\b';

if ( isset($data['email']) && !preg_match($banned, $data['email']) )
{}

or perhaps. do an include that points to a text file? with the domains listed inside?


updated

here is my code..

//Banned Domains
    $banned = 'mailexpire|spamtrail|0815';
    //


    //Emails    
    $email_list = '/^[\w.-]+@((?!'.$banned.').)[\w.-]+\.\w{2,4}$/';             
    if ( isset($data['email']) && preg_match($email_list, $data['email']) )
    {
        $response->addError('Email Addresses from this domain are not allowed, Please try a different email address', 'email');
    }

    else if ( isset($data['email']) && !preg_match($email_list, $data['email']) )
    {
        $query = SK_MySQL::placeholder("SELECT COUNT(`profile_id`) FROM `".TBL_PROFILE."` WHERE `email`='?'",$data['email']);
        if (SK_MySQL::query($query)->fetch_cell()) {
            $error_msg = SK_Language::text('%forms._fields.email.errors.already_exists');
            $response->addError($error_msg,'email');
        }
    }
    //END

for some reason.. its not catching the domains?

  • 写回答

1条回答 默认 最新

  • dpxw17759 2014-01-24 22:31
    关注

    The problem is that you have forgotten to put pattern delimiters:

    $banned = '/^[\w.-]+@((?!' . $list . ').)[\w.-]+\.\w{2,4}$/';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题