Download the PHP package ideaglory/validation without Composer
On this page you can find all versions of the php package ideaglory/validation. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ideaglory/validation
More information about ideaglory/validation
Files in ideaglory/validation
Package validation
Short Description Custom Request Validation and Data Handling
License MIT
Homepage https://ideaglory.com
Informations about the package validation
Custom Request Validation and Data Handling
This class is a custom request validation and data handling class. Its primary function is to handle incoming user data, validate that data based on defined rules, provide meaningful error messages for any validation failures, and optionally sanitize the input data.
The class is designed to be flexible, allowing for:
- Standard and custom validation rules.
- Error handling with detailed validation failure messages.
- Input sanitization, such as trimming strings and cleaning data.
This class ensures that only validated and sanitized data is processed, providing a clean and reliable input handling system for your application.
Available Validation Rules:
- 'required' : Ensures the field is not empty.
- 'string' : Ensures the field is a string.
- 'integer' : Ensures the field is an integer.
- 'min' : Ensures the field value is at least a specified value (numeric or string length).
- 'max' : Ensures the field value does not exceed a specified value (numeric or string length).
- 'email' : Ensures the field is a valid email address.
- 'boolean' : Ensures the field is a boolean value (true or false).
- 'url' : Ensures the field is a valid URL.
- 'alpha' : Ensures the field contains only alphabetic characters (A-Z, a-z).
- 'alpha_dash' : Ensures the field contains only alphanumeric characters, dashes, and underscores.
- 'numeric' : Ensures the field is numeric (integer or float).
- 'equal' : Ensures the field is equal to another field.
- 'in' : Ensures the field value is one of the specified values (comma-separated).
- 'not_in' : Ensures the field value is not one of the specified values (comma-separated).
- 'date' : Ensures the field is a valid date (in 'Y-m-d' format).
Each rule checks a specific condition on the field and returns an error message if the condition is not met. Rules may also accept parameters (e.g., 'min', 'max', 'in', 'not_in') which provide additional validation criteria.
Installation
You can install this package via Composer. Run the following command:
Example Code:
Example Use Cases:
Example 1: Basic String Validation
-
Output (Valid Input):
- Output (Invalid Input):
Example 2: Integer Validation with Range
- Output:
Example 3: Email Validation
-
Output (Valid Email):
- Output (Invalid Email):
Example 4: Custom Validation Rule
-
Output (Valid Input):
- Output (Invalid Input, odd number):
Example 5: Default Values for Missing Fields
- Output:
Example 6: Sanitization
- Output (Sanitized Input):
Example 7: Nested Data Validation
- Output:
Conclusion
This class can handle most validation scenarios, including:
- Basic rules (required, string, integer, email, min, max)
- Custom rules with flexible logic
- Nested field validation using dot notation
- Default values for missing fields
- Input sanitization to trim and escape malicious input
- Customizable error messages
Contributing
Feel free to fork this repository and submit pull requests for improvements or bug fixes.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Author
Created by IdeaGlory.