List of Rules

PHPValidator provides a variety of predefined rules that you can use for data validation. Here is a list of some commonly used rules along with examples of their usage:

  1. Required Rule

    • Ensures that a field is present in the data.
    <?php
    ['username' => 'required']
    
  2. String Rule

    • Checks if a field is of string type.
    <?php
    ['username' => 'string']
    
  3. Email Rule

    • Validates that a field is a well-formed email address.
    <?php
    ['email' => 'email']
    
  4. Max Length Rule

    • Specifies the maximum length of a string field.
    <?php
    ['username' => 'max:25']
    
  5. Confirmed Rule

    • Checks if a field's value is the same as another field (commonly used for password confirmation).
    <?php
    ['password_confirmation' => 'confirmed:password']
    
  6. File Rule

    • Validates that a field is a file upload.
    <?php
    ['file' => 'file']
    
  7. Accepted Rule

    • Validates that a field is "yes", "on", "1", or true. Useful for checkboxes.
    <?php
    ['terms_and_conditions' => 'accepted']
    
  8. Accepted If Rule

    • Validates that a field is accepted if another field is equal to a specified value.
    <?php
    
    ['terms_and_conditions' => 'accepted_if:is_adult,true']
    
  9. ActiveURL Rule

    • Validates that a field is a valid, active URL.
    <?php
    
    ['website' => 'active_url']
    
  10. Alpha Rule

    • Validates that a field contains only alphabetic characters.
    <?php
    
    ['name' => 'alpha']
    
  11. Numeric Rule

    • Validates that a field contains only numeric characters.
    <?php
    
    ['age' => 'numeric']
    
  12. Lowercase Rule

    • Validates that a field contains only lowercase alphabetic characters.
    <?php
    
    ['username' => 'lowercase']
    
  13. Uppercase Rule

    • Validates that a field contains only uppercase alphabetic characters.
    <?php
    
    ['username' => 'uppercase']
    
  14. In Rule

    • Validates that a field's value is among a list of predefined values.
    <?php
    
    ['role' => 'in:admin,editor,viewer']
    
  15. Nullable Rule

    • Allows a field to be null or empty.
    <?php
    
    ['optional_field' => 'nullable']
    
  16. Password Rule

    • Validates that a field is a secure password.
    <?php
    
    ['password' => 'password']
    
  17. Same Rule

    • Validates that a field's value is the same as the value of another field.
    <?php
    
    ['password_confirmation' => 'same:password']
    
  18. Max Length Rule

    • Specifies the minimum length of a string field.
    <?php
    
    ['username' => 'min:8']
    
  19. Not In Rule

    • Validates that a field's value is not in a specified set.
    <?php
    
    ['value' => 'not_in:foo,bar']
    
  20. Required With Rule

    • Requires the field to be present if another specified field is present.
    <?php
    
    ['firstname' => 'required_with:lastname',]
    
  21. Valid IP Rule

    • Validates that a field's value is a valid IP address.
    <?php
    
    ['client_ip' => 'ip',]
    
  22. Json Rule

    • Validates that a field's value is a valid JSON string.
    <?php
    
    ['config' => 'json',]
    
  23. URL Rule

    • Validates that a field's value is a valid URL.
    <?php
    
    ['website' => 'url',]
    
  24. Alpha Numeric Rule

    • Validates that a field's value contains only alphanumeric characters.
    <?php
    
    ['pseudo' => 'alpha_num',]
    
  25. Boolean Rule

    • Validates that a field's value is a boolean.
    <?php
    
    ['is_admin' => 'bool',]
    
  26. Size Rule

    • Validates that the size of a string, integer, array, or file is equal to a specified value.
    <?php
    
        [
            'string' =>'size:7', // strlen(string) == 7
            'integer' =>'size:7', // integer == 7
            'array' =>'size:7', // count(array) == 7
            'file' =>'size:512', // file size (kb) == 512
        ]