Tuesday, September 16, 2014

Codeigniter validate required field,email and passwords.



If we want to validate required field.we can add required command in view where we need to give input.










As you can see we can use "required" for any kind of input type.
Then we have to call controller and check set the validation rules.





First we have to load the  codeigniter validation Library(Line:157).
Then we can use set_rules() method to set rules.In  this method we can pass three parameters.
  1. The field name - the exact name you've given the form field.
  2. A "human" name for this field, which will be inserted into the error message. For example, if your field is named "user" you might give it a human name of "Username".
  3. The validation rules for this form field.

Validation Rules:
trim: 
It removes white space from the beginning and end of an input string.

required:
Checks that the resulting string is non-empty

valid_email:
Checks that it is a valid email address

xss_clean:
removes malicious data.

matches[]:
The password field must match the password confirmation field.

If user done any mistake we can identify that and simply use set_message() function to display error message. 










Tagged: ,

0 comments: