Posted By

myke on 07/20/10


Tagged

form validation codeigniter


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

melik


Codeigniter Numeric Dash Validation


 / Published in: PHP
 

run as callback from formvalidation->setrules ex: $this->formvalidation->setrules('ccnumber','Credit Card #','required|maxlength[20]|callbackalphadashspace');

  1. function alpha_dash_space($str)
  2. {
  3. if (! preg_match("/^([-0-9])+$/i", $str))
  4. {
  5. $this->form_validation->set_message('alpha_dash_space', 'The %s field may only contain numeric characters and dashes.');
  6. return FALSE;
  7. }
  8. else
  9. {
  10. return TRUE;
  11. }
  12. }

Report this snippet  

You need to login to post a comment.