You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you don't know about langs name you can see [Support Languages](#support-languages) section.
56
62
63
+
# Configurations
64
+
65
+
If you may use rules with string like `ValidPhone`, you need to change the config option to `true`:
66
+
67
+
```php
68
+
/*
69
+
* If you want to use rules like 'required|ValidPhone' in your validations, you can change it to true.
70
+
*/
71
+
'using_container' => false,
72
+
```
73
+
74
+
If `using_container` is set to true, you might have rules like this:
75
+
76
+
```php
77
+
'phone_number' => 'required|ValidPhone',
78
+
```
79
+
And `ValidPhone` would be a class that is resolved via the service container to check the validity of the phone number.
80
+
57
81
# Usage
58
82
59
83
You can use `Laravel-Validate Rules` very simply. You can use the `new` keyword before the rule name.
@@ -141,6 +165,58 @@ Also, you can make <a href="https://github.com/milwad-dev/laravel-validate/pulls
141
165
-[x] Ukrainian (uk)
142
166
-[x] Chinese (zh_CN)
143
167
168
+
# Adding Custom Phone Country Validator
169
+
170
+
If you need to add a custom phone number validator for a specific country, follow the steps below.
171
+
172
+
### 1. Create Your Custom Validator Class
173
+
174
+
First, you need to create a custom validator class that implements the `Milwad\LaravelValidate\Utils\CountryPhoneValidator` contract. This contract ensures that your custom validator adheres to the required structure and functionality.
175
+
176
+
```php
177
+
namespace App\Validators;
178
+
179
+
use Milwad\LaravelValidate\Utils\CountryPhoneValidator;
180
+
181
+
class CustomPhoneValidator implements CountryPhoneValidator
182
+
{
183
+
/**
184
+
* Validate the phone number for the custom country.
185
+
*/
186
+
public function validate(string $phoneNumber): bool
187
+
{
188
+
// Implement the phone number validation logic for your country
189
+
// Example: Check if the phone number matches a specific pattern
### 2. Add the Validator to the Configuration File
196
+
197
+
Once you've created the custom validator class, add it to the configuration file (`config/laravel-validate.php`) under the `'phone-country'` array.
198
+
199
+
For example, if you're adding a validator for the country `XY`:
200
+
201
+
```php
202
+
'phone-country' => [
203
+
// Existing validators...
204
+
'XY' => \App\Validators\CustomPhoneValidator::class, // Custom country
205
+
],
206
+
```
207
+
208
+
This tells the system to use your custom validator for phone numbers from country `XY`.
209
+
210
+
### 3. Validation Usage
211
+
212
+
Once your custom validator is set up, you can use it in your application like any other validator:
213
+
214
+
```php
215
+
return [
216
+
'phone_ir' => [new ValidPhoneNumber('XY')],
217
+
];
218
+
```
219
+
144
220
# License
145
221
146
222
* This package is created and modified by <ahref="https://github.com/milwad-dev"target="_blank">Milwad Khosravi</a> for Laravel over more than 9 and has been released under the MIT License.
Copy file name to clipboardExpand all lines: docs/1.x/valid-even-number.md
+2
Original file line number
Diff line number
Diff line change
@@ -9,3 +9,5 @@ return [
9
9
'number' => ['required', new ValidEvenNumber()], // number => 1024
10
10
];
11
11
```
12
+
13
+
> Consider installing the `gmp` extension to significantly enhance performance when working with large numbers. It can greatly optimize your calculations and improve efficiency.
Copy file name to clipboardExpand all lines: docs/1.x/valid-odd-number.md
+2
Original file line number
Diff line number
Diff line change
@@ -9,3 +9,5 @@ return [
9
9
'number' => ['required', new ValidOddNumber()], // number => 4321
10
10
];
11
11
```
12
+
13
+
> Consider installing the `gmp` extension to significantly enhance performance when working with large numbers. It can greatly optimize your calculations and improve efficiency.
0 commit comments