Codeigniter Numeric Dash Validation


/ Published in: PHP
Save to your folder(s)

run as callback from form_validation->setrules
ex:
$this->form_validation->set_rules('cc_number','Credit Card #','required|max_length[20]|callback_alpha_dash_space');


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.