我已经制作了一个实用工具,现在当用户申请忘记密码时,他会显示一个文本框,在那里他可以输入他的电子邮件地址或密码,如何验证电子邮件地址,因为我已经申请了valid_email,它将拒绝密码或我应该显示两个字段,用户必须输入其中一个,但如何验证他必须输入其中一个字段?
答案 0 :(得分:1)
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', 'Email', 'valid_email');
$this->form_validation->set_rules('email', '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;
}
试试这个。或了解更多详情:
http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html