check (method)

Last updated: Fri, Apr 14, 2023 3:56 pm
Return to Knowledgebase


The check() method in the Validate class checks the validity of input data based on a set of predefined rules.




# Parameter Data Type Required Description
1 $source array Yes An array containing the data to be validated
2 $items=[] array No An array containing the rules that the data must adhere to
3 $sanitize=false bool No A boolean value indicating whether or not to sanitize the data before validating it

Further Documentation:

The method first initializes an empty array to store any validation errors that may occur. It then iterates over each item in the $items array and checks it against the corresponding data in the $source array.

If the $sanitize parameter is set to true, the method sanitizes the input data before validating it. If the item is required and is not present in the input data, an error message is added to the validation errors array.

If the item is present in the input data, the method applies the validation rules defined in the $items array. The supported validation rules include min, max, matches, unique, unique_update, is_numeric, valid_email, is_not_email, valid_email_beta, <, >, <=, >=, !=, ==, is_integer, is_timezone, in, is_datetime, is_in_array, is_in_database, is_valid_north_american_phone.

If any validation errors occur during the iteration, they are added to the validation errors array. The method then returns the $this object, which can be used to chain validation methods together.

Overall, the check() method provides a flexible and comprehensive way to validate input data in UserSpice, and is an important part of the data validation and sanitization process in the framework.