• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
numeric form validation does not work


I have a form with an input field:
$espresso = array('name'=>'espresso', 'size'=>'1', 'maxlength'=>'3', 'value'=>set_value('espresso'));

In my controller I have this validation rule:

$this->form_validation->set_rules('espresso', 'Qty', 'trim|numeric');

I put a letter in the espresso field, submit the form and I don't get any error.

If I try this rule:

$this->form_validation->set_rules('espresso', 'Qty', 'trim|required');

I get a nice beatiful error that the field is required.

Why don't I get the error for the numeric rule?


I also having the similar problem in password and confirm password field . But i solve it in a different way.
User the callback function .
$this->form_validation->set_rules('espresso', 'Qty', 'trim|numeric');

$this->form_validation->set_rules('espresso', 'Qty', 'trim|callback_numeric_check');  

function numeric_check($num){
   return false;
perform the numeric check .. or paste the code from form_validation library into it.

But it is not the actual solution but its the last solution. Actually numeric would work. But in case if you cant solve the problem follow the above approach.

Thank you, I will try your way until we get another solution.

Will post here if I find something.

Hmmm, at a casual glance it should work. Have you tried either of these rules instead:

Hi Boltsabre,

I tried integer as well, did not work.

It suddenly started working, don't know how and why.

That is really strange... You weren't defining two sets of validation rulesets, overriding the first one by any chance???

$this->form_validation->set_rules('espresso', 'Qty', 'trim|numeric');
$this->form_validation->set_rules('espresso', 'Qty', 'trim');
And in fact, I'm not even sure if this would override the first set, never tested it, just a thought...
Another thought... make sure your virus scan is fully up to date and run a full scan of all your devices...

Yeah, I can't see any reason why numeric would pass with a letter in it (at least the current version of the form validation lib). Might've had something to do with your code elsewhere.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.