pc_*_*_oc 4 php regex validation codeigniter date
我有a的过去日期,textbox
如果日期大于当前日期并且具有格式,我想验证表单提交dd/mm/yyyy
.
在我的form_validation.php中:
'add_prod_serv_fact' => array(
'quantidade_prod' => array('field' => 'quantidade_prod', 'label' => 'Quantidade', 'rules' => 'required|trim|numeric|greater_than[0]|htmlspecialchars'),
'desconto_prod' => array('field' => 'desconto_prod', 'label' => 'Desconto', 'rules' => 'required|trim|numeric|greater_than[-1]|less_than[101]|htmlspecialchars'),
'date' => array('field' => 'date', 'label' => 'Date', 'rules' => 'required|trim|htmlspecialchars')
)
Run Code Online (Sandbox Code Playgroud)
如何验证日期?
你可以先通过正则表达式验证,你应该写一个这样的函数
function validate_date_reg($input)
{
if (preg_match('\d{1,2}/\d{1,2}/\d{4}', $input))
{
return true; // it matched, return true
}
else
{
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
并称之为:
if($this->validate_date_reg($this->input->post('some_data')))
{
// true go ahead......
}
Run Code Online (Sandbox Code Playgroud)
我希望这会对你有所帮助.