From 6290a3276a1b33de42be7a16e906ec0bebd0ed9d Mon Sep 17 00:00:00 2001 From: v1p3r75 Date: Fri, 17 Nov 2023 23:04:31 +0100 Subject: [PATCH 1/2] Updated documentation --- README.md | 60 +++++++++++++++++++++++++++++++++++++- tests/Feature/RuleTest.php | 1 - 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d88547d..499df02 100644 --- a/README.md +++ b/README.md @@ -185,8 +185,66 @@ PHPValidator provides a variety of predefined rules that you can use for data va ```php 'username' => 'min_length: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' => 'valid_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_numeric', + ``` + +25. **Boolean Rule** + - Validates that a field's value is a boolean. + + ```php + 'is_admin' => 'boolean', + ``` + +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 + ] + ``` ## Custom Rule In addition to the predefined rules, you can create custom validation rules by implementing the `RuleInterface`. Here's an example of how to create and use a custom rule: diff --git a/tests/Feature/RuleTest.php b/tests/Feature/RuleTest.php index 11a5d13..6b3cf3f 100644 --- a/tests/Feature/RuleTest.php +++ b/tests/Feature/RuleTest.php @@ -4,7 +4,6 @@ use BlakvGhost\PHPValidator\Rules\AcceptedIfRule; use BlakvGhost\PHPValidator\Rules\AcceptedRule; use BlakvGhost\PHPValidator\Rules\ActiveURLRule; -use BlakvGhost\PHPValidator\Rules\AlphaNumeric; use BlakvGhost\PHPValidator\Rules\AlphaNumericRule; use BlakvGhost\PHPValidator\Rules\AlphaRule; use BlakvGhost\PHPValidator\Rules\BooleanRule; From 2711a190eddaae3791f51ce3e22f4fa61a0dea17 Mon Sep 17 00:00:00 2001 From: v1p3r75 Date: Fri, 17 Nov 2023 23:12:07 +0100 Subject: [PATCH 2/2] Updated documentation --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 499df02..218f8e9 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ try { // $data = $_POST; $validator = new Validator($data, [ - 'username' => 'required|string:25', + 'username' => 'required|string', 'email' => 'required|email', 'score' => ['required','max_length:200', new CustomRule()], 'password' => new CustomRule(),