2011-12-03 79 views

回答

2
$this->form_validation->set_rules('field[]', 'The field', 'numeric|xss_clean'); 

這在理論上應該是足夠的,因爲該字段沒有被設置爲必需的。

+1

但是,它返回錯誤。可能它是一個Codeigniter的錯誤?我正在使用2.0.3 – sunpietro

0

我想你的意思是「使用數組作爲字段名

你可以看看this page

2

但是,它返回我的錯誤

那麼也許一個額外步驟:

if (!empty($this->input->post('field[]'))) 
{ 
    $this->form_validation->set_rules('field[]', 'The field', 'numeric|xss_clean'); 
} 
+0

我需要測試它。 – sunpietro

+0

@sunpietro - 你有機會測試它嗎? – stealthyninja

+0

錯字,代碼應該讀$ this-> input-> post – Randall

0

對於10位數的電話號碼:

$this->form_validation->set_rules('mobile', 'Mobile Number ', 'required|regex_match[/^[0-9]{10}$/]'); //{10} for 10 digits number