我想检查值是否不是整数和浮点数,我已经编写了表单验证,如下所示,
$this->form_validation->set_rules('charge_hour', 'Per hour', 'xss_clean|callback_money_type');
$this->form_validation->set_rules('charge_day', 'Per day', 'xss_clean|callback_money_type');
$this->form_validation->set_rules('charge_weekly', 'Per week', 'xss_clean|callback_money_type');
$this->form_validation->set_rules('charge_monthly', 'Per month', 'xss_clean|callback_money_type');
所有文本文件的通用回调函数是
money_type()
public function money_type($charge)
{
if (is_float($charge) == false && is_int($charge) == false && $charge >= 0)
{
$this->form_validation->set_message('{WHAT TO ENTER HERE}', 'Enter valid charges for space.');
return FALSE;
}
else
{
return TRUE;
}
}
在验证过程中,我如何找出{此处输入什么}?字段名是charge-hour、charge-day、charge-weekly和charge-monthly中的任意一个?这样表单验证将为每个字段显示不同的错误消息。
谢谢。
最佳答案
$this->form_validation->set_message('money_type','%s my message');
https://www.codeigniter.com/user_guide/libraries/form_validation.html#callbacks-your-own-validation-methods