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
Copy file name to clipboardExpand all lines: README.md
+50Lines changed: 50 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -158,6 +158,56 @@ Also, you can make <a href="https://github.com/milwad-dev/laravel-validate/pulls
158
158
-[x] Ukrainian (uk)
159
159
-[x] Chinese (zh_CN)
160
160
161
+
# Adding Custom Phone Country Validator
162
+
163
+
If you need to add a custom phone number validator for a specific country, follow the steps below.
164
+
165
+
### 1. Create Your Custom Validator Class
166
+
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.
167
+
168
+
```php
169
+
namespace App\Validators;
170
+
171
+
use Milwad\LaravelValidate\Utils\CountryPhoneValidator;
172
+
173
+
class CustomPhoneValidator implements CountryPhoneValidator
174
+
{
175
+
/**
176
+
* Validate the phone number for the custom country.
177
+
*/
178
+
public function validate(string $phoneNumber): bool
179
+
{
180
+
// Implement the phone number validation logic for your country
181
+
// Example: Check if the phone number matches a specific pattern
### 2. Add the Validator to the Configuration File
188
+
Once you've created the custom validator class, add it to the configuration file (`config/phone-country.php`) under the `'phone-country'` array.
189
+
190
+
For example, if you're adding a validator for the country `XY`:
191
+
192
+
```php
193
+
'phone-country' => [
194
+
// Existing validators...
195
+
'XY' => \App\Validators\CustomPhoneValidator::class, // Custom country
196
+
],
197
+
```
198
+
199
+
This tells the system to use your custom validator for phone numbers from country `XY`.
200
+
201
+
### 3. Validation Usage
202
+
203
+
Once your custom validator is set up, you can use it in your application like any other validator:
204
+
205
+
```php
206
+
return [
207
+
'phone_ir' => [new ValidPhoneNumber('XY')],
208
+
];
209
+
```
210
+
161
211
# License
162
212
163
213
* 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.
0 commit comments