Hi,
What does the trim form validation rule actually do and when should I use it?
Thanks
Hi,
What does the trim form validation rule actually do and when should I use it?
Thanks
It removes whitespace from the beginning and end of an input string.
You can think of validation rules as a pipeline of routines run on the input. For example :
$this->form_validation->set_rules('email', 'email', 'trim|required|valid_email');
When validating the email input CodeIgniter :
The trim routine is normally run before other routines and placed at the front of the list.
You should use it when you want to ignore the starting and trailing whitespace in the input. Perhaps the user has accidentally typed a space character after an email address in a HTML form. The space character should not be taken as part of the email address and should be removed.
You can use any in-built PHP function that takes one argument and returns a value or true or false as a form validation rule. So trim isn't actually a Codeigniter specific function, it's a PHP one.
Some other in-built PHP functions you can use are; is_int (checks if a number is an integer), ltrim (trims left of a string), rtrim (trims the right of a string), sha1, md5, etc.