CodeIgniter Forums

Full Version: Full name validation in codeigniter
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[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 ????

El Forum

[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-gui...#callbacks

El Forum

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

El Forum

[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;
  }
}