CodeIgniter 表单验证 - 如何使其不区分大小写
我正在使用 Code Igniter 2,如果用户输入相同的电子邮件地址但在不同的情况下,以下代码不会验证,例如: [电子邮件受保护] 和 [电子邮件受保护] 我希望即使用户使用不同的情况,也可以验证它是否是同一封电子邮件。
$this->form_validation->set_rules('password', 'Password', 'required|trim|xss_clean');
$this->form_validation->set_rules('email', 'Email', 'required|valid_email|trim');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('login_view', $data);
}
else
{
I am using Code Igniter 2, and the following code doesn't validate in case the user entered the same email address but in different cases, for example: [email protected] and [email protected]
I want this to validate if it's the same email even if the user used different cases.
$this->form_validation->set_rules('password', 'Password', 'required|trim|xss_clean');
$this->form_validation->set_rules('email', 'Email', 'required|valid_email|trim');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('login_view', $data);
}
else
{
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
任何接受一个参数的 PHP 函数都可以在验证类中使用。
来自手册
这意味着您只需修改验证规则即可
注意 的使用规则中的 strtolower() 函数。
Any PHP function which accepts one parameter can be used in the validation class.
From the manual
Which means you can just amend your validation rule to
Note the use of the strtolower() function in the rules.
您需要在控制器内创建一个回调函数:
然后将 set_rules 修改为此
或者您可以扩展 form_validation 类并覆盖
valid_email
函数。You need to create a callback function inside your controller:
Then modify the set_rules to this
Alternatively you could extend the form_validation class and overwrite the
valid_email
function.这样做:
希望有帮助
Do this as:
Hope it helps