Here is a more complex validation example that takes advantage of some of these built-in validation rules: Two validation rules are defined for login: it should contain letters and numbers only, and its length should be between 5 and 15.The password field should be a minimum of 8 characters long.The email should be a valid email address, and born should be a valid date.
Defining validation rules enables Cake PHP’s automagic showing of error messages in forms if the data submitted does not follow the defined rules.
Cake PHP has many validation rules and using them can be quite easy.
Some of the built-in rules allow you to verify the formatting of emails, URLs, and credit card numbers – but we’ll cover these in detail later on.
What we’ll cover in this section is the model side of things.
Essentially: what happens when you call the save() method of your model.
For more information about how to handle the displaying of validation errors, check out array is added to the User Model, but the array contains no validation rules.Assuming that the users table has login, password, email and born fields, the example below shows some simple validation rules that apply to those fields: This last example shows how validation rules can be added to model fields.Data validation is an important part of any application, as it helps to make sure that the data in a Model conforms to the business rules of the application.For example, you might want to make sure that passwords are at least eight characters long, or ensure that usernames are unique.Defining validation rules makes form handling much, much easier.There are many different aspects to the validation process.