简体   繁体   中英

form validation for a text box to enter a number between 0-100 in codeigniter

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

试试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');

You can try custom validation like this :

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'
    );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM