DataValidator Class Documentation

DataValidator is a fluent PHP class (namespace: Nobanno) for validating and sanitizing data from user input, supporting a wide range of rules and types. All validation failures throw a Nobanno\ValidationException.

Namespace: Nobanno
Exception: Nobanno\ValidationException

1. Basic Usage

use Nobanno\DataValidator;
use Nobanno\ValidationException;

try {
    $value = (new DataValidator())
        ->title('Customer Name')
        ->post('customer_name')
        ->required()
        ->asAlphabetic(true)
        ->minLen(3)
        ->maxLen(50)
        ->sanitize()
        ->validate();
    // Use $value
} catch (ValidationException $e) {
    echo $e->getMessage();
}

2. Setting the Value

3. Label/Title

4. Sanitization

5. Required/Optional

6. Language Checks

7. Type Checks

8. Length & Range

9. Miscellaneous

10. Finalizing

11. Example: Validating a POST Email

try {
    $email = (new DataValidator())
        ->title('Email')
        ->post('email')
        ->required()
        ->asEmail()
        ->sanitize()
        ->validate();
} catch (ValidationException $e) {
    echo $e->getMessage();
}

12. Exception Handling

All validation failures throw ValidationException with a descriptive message. Use try/catch to handle errors.

13. Tips & Best Practices

14. References