加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – Codeigniter自定义电子邮件验证规则

发布时间:2020-12-13 13:38:28 所属栏目:PHP教程 来源:网络整理
导读:有人可以就如何为Codeigniter创建自定义验证规则提供一些建议. 我正在研究的网站是针对大学生的,只允许用户在使用他们的大学电子邮件地址时进行注册. 以下是我尝试实现的验证类型的示例: 仅允许以以下结尾的电子邮件: array( '0' = '@uni-email-1.com','1'
有人可以就如何为Codeigniter创建自定义验证规则提供一些建议.

我正在研究的网站是针对大学生的,只允许用户在使用他们的大学电子邮件地址时进行注册.

以下是我尝试实现的验证类型的示例:

仅允许以以下结尾的电子邮件:

array(
    '0' => '@uni-email-1.com','1' => '@uni-email-2.com','2' => '@uni-email-3.com','3' => '@uni-email-4.com',);

我仍然是codeigniter的新手,我不知道如何创建这种类型的验证.

非常感谢任何帮助!

谢谢

当然,这是怎么回事?
function index()
{
    $this->load->helper(array('form','url'));

    $this->load->library('form_validation');


    $this->form_validation->set_rules('email','Email','required');
    $this->form_validation->set_rules('email','valid_email');
    $this->form_validation->set_rules('email','callback_email_check');

    if ($this->form_validation->run() == FALSE)
    {
        //fail
    }
    else
    {
        //success
    }
}

function email_check($str)
{

    if (stristr($str,'@uni-email-1.com') !== false) return true;
    if (stristr($str,'@uni-email-2.com') !== false) return true;
    if (stristr($str,'@uni-email-3.com') !== false) return true;

        $this->form_validation->set_message('email','Please provide an acceptable email address.');
        return FALSE;

}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读