2014-04-05 61 views
0

我做了一個實用程序,現在當用戶申請忘記密碼時,他顯示了一個文本框,他可以在其中輸入他的電子郵件地址或密碼,如何驗證電子郵件地址,因爲我有我應用valid_email,它會拒絕密碼或者我應該顯示兩個字段,用戶必須輸入任一個,但是如何驗證他必須輸入其中一個字段?表單驗證碼點火器

+0

請澄清你的問題。你是否要求驗證電子郵件,即它是否存在於數據庫中?或者您希望該用戶應該輸入任一字段? –

+0

有效的電子郵件方式,一種有效的電子郵件格式 – avinashizhere

回答

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