Validation

Validation is a process of checking to ensure that the data entered is sensible and reasonable and that it fulfills its intended purpose.

Quantum provides a `Validation` library which built on Wixel/GUMP validation class and makes the validation process easy and transparent.
To start validating the data you will need to specify validation rules. In the Quantum framework validation rules can be placed on controllers or on modules.

A simple rules configuration has similar structure:


$rules = [
    'first_name' => 'required',
    'last_name' => 'required',
    'age' => 'numeric',
    'email' => 'required|valid_email|unique,User',
    'phone' => 'numeric'
];

        

Once rules are spcified, we can check the input parameters against validation rules


    $validated = Validation::is_valid(Request::all(), $rules);

        

The is_valid() method of Validation class returns true if data is valid, otherwhise error message will be returned.


if ($validated === true) {
    // Data is valid
} 
else {
    // Data is invalid and $validated contains the error messages
}

        

Below is a list of validation rules that are available to use:

  • required - Ensures the specified key value exists and is not empty
  • valid_email - Checks for a valid email address
  • max_len,n - Checks key value length, makes sure it's not longer than the specified (n) length.
  • min_len,n - Checks key value length, makes sure it's not shorter than the specified (n) length.
  • exact_len - Ensures that the key value length precisely matches the specified (n) length.
  • alpha - Ensure only alpha characters are present in the key value
  • alpha_numeric - Ensure only alpha-numeric characters are present in the key value
  • alpha_dash - Ensure only alpha-numeric characters + dashes and underscores are present in the key value
  • numeric - Ensure only numeric key values
  • integer - Ensure only integer key values
  • boolean - Checks for PHP accepted boolean values, returns TRUE for "1", "true", "on" and "yes"
  • float - Checks for float values
  • valid_url - Check for valid URL or subdomain
  • url_exists - Check to see if the url exists and is accessible
  • valid_ip - Check for valid generic IP address
  • valid_cc - Check for a valid credit card number (Uses the MOD10 Checksum Algorithm)
  • valid_name - Check for a valid credit card number (Uses the MOD10 Checksum Algorithm)
  • contains,n - Verify that a value is contained within the pre-defined value set
  • contains_list - validation.contains_list
  • street_address - validation.street_address
  • date - Determine if the provided input is a valid date (ISO 8601)
  • min_numeric - Determine if the provided numeric value is higher or equal to a specific value
  • max_numeric - Determine if the provided numeric value is lower or equal to a specific value
  • phone_number - Validate phone numbers that match the following examples
  • unique - Determine if the field under validation is unique in a given database table.

Please refer to Wixel/GUMP documentation for more available validation rules.

<< Prev Next >>