1- # validator
1+ # Validator
22
33Data validation composer package.
44
55## Installation
66
7+ Install using composer.
8+
9+ ```
10+ composer require codesvault/validator
11+ ```
12+
713<br >
814<br >
915
@@ -14,6 +20,8 @@ $validator = Validator::validate(
1420 [
1521 'username' => 'required|stringOnly',
1622 'full_name' => 'stringWithSpace',
23+ 'password' => 'required|min:8',
24+ 'email' => 'required|email',
1725 ],
1826);
1927```
@@ -36,13 +44,38 @@ $validator = Validator::validate(
3644```
3745
3846<br >
47+ <br >
48+
49+ ## Handling Errors
3950
40- ` validate ` method will return an object of ` ValidationEngine ` class.
51+ If any data is invalid then ` error ` method will return error messages array. Otherwise it'll return false.
52+ <br >
53+ ` getData ` method will return validated data array.
4154
4255``` php
43- if ($validator->error()) {
44- return $validator->getErrorList();
56+ $error = $validator->error();
57+ if ($error) {
58+ return $error;
4559}
46-
47- return $validator->getData();
60+ $validator->getData();
4861```
62+
63+ <br >
64+ <br >
65+
66+ ## Available Rules
67+
68+ | Rule | Description |
69+ | --- | --- |
70+ | required | Check if the field under validation is present in the input data and is not empty. |
71+ | email | Check if the field under validation is valid email address. |
72+ | url | Check if the field under validation is valid url. |
73+ | string | Check if the field under validation is string. |
74+ | stringOnly | Check if the field under validation is only string charecters. |
75+ | stringWithSpace | Check if the field under validation is string with space. |
76+ | stringWithNumber | Check if the field under validation is string with number. |
77+ | StringWithDash | Check if the field under validation is string with dash and underscore. |
78+ | min | Check if the field under validation is greater than or equal to the given value. |
79+ | max | Check if the field under validation is less than or equal to the given value. |
80+ | integer | Check if the field under validation is integer. |
81+ | sameValue | Check if the field under validation is same as the given value. |
0 commit comments