Welcome Guest, Not a member yet? Register   Sign In
validation rules from 1 to 9
#1

[eluser]aktosci[/eluser]
I would like to check a value from 1 ( min ) to 9 ( max ) :

I did that

Code:
$this->form_validation->set_rules('licoef', 'coef', 'integer'|'exact_length[1]');

but when I put 12 I don't get an error message
#2

[eluser]Dam1an[/eluser]
The rules all need to be one string,
Code:
// So instead of
'integer'|'exact_length[1]'
// try
'integer|exact_length[1]'
#3

[eluser]TheFuzzy0ne[/eluser]
That's because your syntax is incorrect. The rules are a single string parameter:
Code:
$this->form_validation->set_rules('licoef', 'coef', 'integer|exact_length[1]');

EDIT: Poop.
#4

[eluser]aktosci[/eluser]
Great !!!! It works !! thank you

Now I would like to enlarge the question ( for the future ) how to check a min and max value for example ( from 5 to 15 )?
#5

[eluser]TheFuzzy0ne[/eluser]
Create a custom method in your controller.

Code:
function _validate_liceof($str="")
{
    $str = (int)$str;

    if ($str < 5 || $str > 15)
    {
        $this->form_validation->set_message('_validate_liceof', 'You must enter a number between 5 and 15');

        return FALSE;
    }

    return TRUE;
}




Theme © iAndrew 2016 - Forum software by © MyBB