CodeIgniter Forums
Full name validation in codeigniter - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Full name validation in codeigniter (/thread-54362.html)



Full name validation in codeigniter - El Forum - 09-05-2012

[eluser]Aqsa Jamil[/eluser]
Which validation rule is used to validate full name field in codeigniter.
I need to place a validation rule that full name field should accept space between first name and last name

Can any one help me ????


Full name validation in codeigniter - El Forum - 09-05-2012

[eluser]Sanjay Sarvaiya[/eluser]
you can use callback function in validation.
if you have not idea about callback please read this userguide.
http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html#callbacks


Full name validation in codeigniter - El Forum - 09-08-2012

[eluser]Aqsa Jamil[/eluser]
How to write callback function for checking if user is entering space between first name and last name???


Full name validation in codeigniter - El Forum - 09-08-2012

[eluser]Sanjay Sarvaiya[/eluser]
I think you have not read user guide Every things are described on it.
in your case your call back function will be shaw in bellowed Example.
may this help you.
Code:
//set your validation rules
$this->form_validation->set_rules('name', 'Full Name', 'callback_space_check');

your call back function will be like...
public function space_check($str) {
   $pos = strrpos($str, " ");
   if ($pos === false) { // note: three equal signs
    // not found...
    $this->form_validation->set_message('space_check', 'The %s field can not contain SPACE BTW First name and Last Name');
    return FALSE;
  }
  else  {
    return true;
  }
}