Welcome Guest, Not a member yet? Register   Sign In
Form Validation (extentions) Greater than / Less than a curtain number

I am quite new to working with codeigniter framework and was wondering if someone can help me add to the form validation.

Basically when someone fills up a form I need it to check and make sure the number they entered are:

- Greater than X
- Less than Y

How can i add a new part to the current existing form validation of codeigniter to do this?


you can use from form validation the already defined rules greater_than and less than

or you can combine them in one rule extending form_validation
is_between[4.15] for 4 < val < 15

public function is_between($str,$val)
   if (! is_numeric($str))
      return FALSE;

   list($val, $max)=explode('.', $val);
   return (($str > $val) AND ($str < $max));

Thanks a lot.

For some reason the greater_than and less_than did not work, I will go with this other option and make a callback.

dunno if anyone modified it yet or not, but i changed the greater and less_than validation with this:

function greater_than($str, $field)
if ( ! is_numeric($str))
return FALSE;
if ( ! is_numeric($field))
$min = $_POST[$field];
else $min = $field;
return $str > $min;

the logic is captured by function matches. i modified it cause i'm comparing some number with other number in 2 inputs field. Tongue. by doing this, i can validating my own number or from input field.


Theme © iAndrew 2016 - Forum software by © MyBB