对文本框进行表单验证,以在codeigniter中输入0-100之间的数字

时间:2013-12-26 05:35:40

标签: php codeigniter

$this->form_validation->set_rules('calls_abandoned', 'Calls
abandoned',
'required|integer|greater_than_or_equal_to[0]|less_than[101]|decimal');

2 个答案:

答案 0 :(得分:1)

尝试http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html#rulereference

中的规则is_natural
$this->form_validation->set_rules('calls_abandoned', 'Calls abandoned', 'required|integer|is_natural|less_than[101]|decimal');

答案 1 :(得分:0)

您可以尝试这样的自定义验证:

function maximCheck($num)
{
    if ($num > 0 && $num < 100)
    {
         return TRUE;

    }
    else
    {
        $this->form_validation->set_message(
                        'your_field',
                        'The %s field must be in 1 to 100'
                    );
        return FALSE;
    }
}


$this->form_validation->set_rules(
        'your_field', 'Your Number', 'callback_maximCheck'
    );