Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ return [
| 39 | [ValidUuid](https://github.com/milwad-dev/laravel-validate/blob/1.x/docs/1.x/valid-uuid.md) | Validate uuid for ex (123e4567-e89b-12d3-a456-426655440000) |
| 40 | [ValidVatId](https://github.com/milwad-dev/laravel-validate/blob/1.x/docs/1.x/valid-vatid.md) | Validate european VAT ID ex (EL123456789123) |
| 41 | [ValidLandlineNumber](https://github.com/milwad-dev/laravel-validate/blob/1.x/docs/1.x/valid-landline-number.md) | Validate landline number |
| 42 | [ValidIranPlate](https://github.com/milwad-dev/laravel-validate/blob/1.x/docs/1.x/valid-iran-plate.md) | Validate Iran car license plate |

<a name="support-languages"></a>

Expand Down
15 changes: 15 additions & 0 deletions docs/1.x/valid-iran-plate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## ValidIranPlate

If you want to validate the Iran license plate number, you can use the `ValidIranPlate` rule:

```php
use Milwad\LaravelValidate\Rules\ValidIranPlate;

return [
'car-plate-number' => ['required', new ValidCarNumber()],
/*
* Iran plate license number:
* 32 ی 321 ایران 45
*/
];
```
24 changes: 24 additions & 0 deletions src/Rules/ValidIranPlate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Milwad\LaravelValidate\Rules;

use Illuminate\Contracts\Validation\Rule;

class ValidIranPlate implements Rule
{
/**
* Check License Plate Validator.
*/
public function passes($attribute, $value): bool
{
return preg_match("/^\d{2}\s?[آ-ی]\s?\d{3}\s?ایران\s?\d{2}$/u", $value);
}

/**
* Get the License Plate Validator error message.
*/
public function message(): string
{
return __('validate.iran-plate');
}
}
2 changes: 1 addition & 1 deletion src/Utils/CountryPhoneValidator/IRPhoneValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ class IRPhoneValidator implements CountryPhoneValidator
*/
public function validate($value): bool
{
return preg_match('/^(\+98|0)?9\d{9}$/', $value);
return preg_match('/^(\+98|98|0098|0)?9\d{9}$/', $value);
}
}
2 changes: 2 additions & 0 deletions src/lang/It/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@
'url' => ':attribute non è valido.',
'username' => ':attribute non è valido.',
'uuid' => ':attribute non è valido.',
'landline-number' => ':attribute non è valido.',
'iran-plate' => ':attribute non è valido.',
];
2 changes: 2 additions & 0 deletions src/lang/ar/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@
'url' => ':attribute غير صالح.',
'username' => ':attribute غير صالح.',
'uuid' => ':attribute غير صالح.',
'landline-number' => ':attribute غير صالح.',
'iran-plate' => ':attribute غير صالح.',
];
2 changes: 2 additions & 0 deletions src/lang/az/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@
'url' => ':attribute doğru deyil.',
'username' => ':attribute doğru deyil.',
'uuid' => ':attribute doğru deyil.',
'landline-number' => ':attribute doğru deyil.',
'iran-plate' => ':attribute doğru deyil.',
];
2 changes: 2 additions & 0 deletions src/lang/bn/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@
'url' => ':attribute বৈধ নয়.',
'username' => ':attribute বৈধ নয়.',
'uuid' => ':attribute বৈধ নয়.',
'landline-number' => ':attribute বৈধ নয়.',
'iran-plate' => ':attribute বৈধ নয়.',
];
2 changes: 2 additions & 0 deletions src/lang/ca/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@
'url' => ':attribute no és vàlid.',
'username' => ':attribute no és vàlid.',
'uuid' => ':attribute no és vàlid.',
'landline-number' => ':attribute no és vàlid.',
'iran-plate' => ':attribute no és vàlid.',
];
1 change: 1 addition & 0 deletions src/lang/de/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@
'username' => ':attribute kein gültiger.',
'uuid' => ':attribute kein gültiger.',
'landline-number' => ':attribute kein gültiger.',
'iran-plate' => ':attribute kein gültiger.',
];
2 changes: 2 additions & 0 deletions src/lang/el/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@
'url' => 'Το :attribute δεν είναι έγκυρο.',
'username' => 'Το :attribute δεν είναι έγκυρο.',
'uuid' => 'Το :attribute δεν είναι έγκυρο.',
'landline-number' => 'Το :attribute δεν είναι έγκυρο.',
'iran-plate' => 'Το :attribute δεν είναι έγκυρο.',
];
2 changes: 2 additions & 0 deletions src/lang/en/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@
'url' => 'The :attribute is not valid.',
'username' => 'The :attribute is not valid.',
'uuid' => 'The :attribute is not valid.',
'landline-number' => 'The :attribute is not valid.',
'iran-plate' => 'The :attribute is not valid.',
];
2 changes: 2 additions & 0 deletions src/lang/es/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@
'url' => ':attribute no es válido.',
'username' => ':attribute no es válido.',
'uuid' => ':attribute no es válido.',
'landline-number' => ':attribute no es válido.',
'iran-plate' => ':attribute no es válido.',
];
1 change: 1 addition & 0 deletions src/lang/fa/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@
'username' => 'مقدار :attribute صحیح نمی باشد.',
'uuid' => 'مقدار :attribute صحیح نمی باشد.',
'landline-number' => 'مقدار :attribute صحیح نمی باشد.',
'iran-plate' => 'مقدار :attribute صحیح نمی باشد.',
];
2 changes: 2 additions & 0 deletions src/lang/fr/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@
'url' => ":attribute n'est pas valide.",
'username' => ":attribute n'est pas valide.",
'uuid' => ":attribute n'est pas valide.",
'landline-number' => ":attribute n'est pas valide.",
'iran-plate' => ":attribute n'est pas valide.",
];
2 changes: 2 additions & 0 deletions src/lang/hi/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@
'url' => ':attributeमान्य नहीं है।.',
'username' => ':attributeमान्य नहीं है।.',
'uuid' => ':attributeमान्य नहीं है।.',
'landline-number' => ':attributeमान्य नहीं है।.',
'iran-plate' => ':attributeमान्य नहीं है।.',
];
2 changes: 2 additions & 0 deletions src/lang/id/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@
'url' => ':Attribute tidak valid.',
'username' => ':Attribute tidak valid.',
'uuid' => ':Attribute tidak valid.',
'landline-number' => ':Attribute tidak valid.',
'iran-plate' => ':Attribute tidak valid.',
];
2 changes: 2 additions & 0 deletions src/lang/ja/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@
'url' => ':attribute有効じゃない。',
'username' => ':attribute有効じゃない。',
'uuid' => ':attribute有効じゃない。',
'landline-number' => ':attribute有効じゃない。',
'iran-plate' => ':attribute有効じゃない。',
];
2 changes: 2 additions & 0 deletions src/lang/ko/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@
'url' => ':attribute유효하지 않습니다.',
'username' => ':attribute유효하지 않습니다.',
'uuid' => ':attribute유효하지 않습니다.',
'landline-number' => ':attribute유효하지 않습니다.',
'iran-plate' => ':attribute유효하지 않습니다.',
];
2 changes: 2 additions & 0 deletions src/lang/ku_so/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@
'url' => 'ئەو :attribute هەڵبژێردراوە نادروستە.',
'username' => 'ئەو :attribute هەڵبژێردراوە نادروستە.',
'uuid' => 'ئەو :attribute هەڵبژێردراوە نادروستە.',
'landline-number' => 'ئەو :attribute هەڵبژێردراوە نادروستە.',
'iran-plate' => 'ئەو :attribute هەڵبژێردراوە نادروستە.',
];
2 changes: 2 additions & 0 deletions src/lang/mk/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@
'url' => 'Невалидна вредност :attribute',
'username' => 'Невалидна вредност :attribute',
'uuid' => 'Невалидна вредност :attribute',
'landline-number' => 'Невалидна вредност :attribute',
'iran-plate' => 'Невалидна вредност :attribute',
];
2 changes: 2 additions & 0 deletions src/lang/nl/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@
'url' => 'De :attribute is niet geldig.',
'username' => 'De :attribute is niet geldig.',
'uuid' => 'De :attribute is niet geldig.',
'landline-number' => 'De :attribute is niet geldig.',
'iran-plate' => 'De :attribute is niet geldig.',
];
2 changes: 2 additions & 0 deletions src/lang/pt_BR/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@
'url' => 'O :attribute não é válido.',
'username' => 'O :attribute não é válido.',
'uuid' => 'O :attribute não é válido.',
'landline-number' => 'O :attribute não é válido.',
'iran-plate' => 'O :attribute não é válido.',
];
2 changes: 2 additions & 0 deletions src/lang/ru/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@
'url' => ':attribute не действует.',
'username' => ':attribute не действует.',
'uuid' => ':attribute не действует.',
'landline-number' => ':attribute не действует.',
'iran-plate' => ':attribute не действует.',
];
2 changes: 2 additions & 0 deletions src/lang/si/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@
'url' => ':attribute වලංගු නොවේ.',
'username' => ':attribute වලංගු නොවේ.',
'uuid' => ':attribute වලංගු නොවේ.',
'landline-number' => ':attribute වලංගු නොවේ.',
'iran-plate' => ':attribute වලංගු නොවේ.',
];
2 changes: 2 additions & 0 deletions src/lang/sv/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@
'url' => 'Värdet :attribute är inte korrekt.',
'username' => 'Värdet :attribute är inte korrekt.',
'uuid' => 'Värdet :attribute är inte korrekt.',
'landline-number' => 'Värdet :attribute är inte korrekt.',
'iran-plate' => 'Värdet :attribute är inte korrekt.',
];
2 changes: 2 additions & 0 deletions src/lang/tr/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@
'url' => ':attribute doğru değil.',
'username' => ':attribute doğru değil.',
'uuid' => ':attribute doğru değil.',
'landline-number' => ':attribute doğru değil.',
'iran-plate' => ':attribute doğru değil.',
];
2 changes: 2 additions & 0 deletions src/lang/uk/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@
'url' => ':attribute не є дійсним.',
'username' => ':attribute не є дійсним.',
'uuid' => ':attribute не є дійсним.',
'landline-number' => ':attribute не є дійсним.',
'iran-plate' => ':attribute не є дійсним.',
];
2 changes: 2 additions & 0 deletions src/lang/zh_CN/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@
'url' => ':attribute无效.',
'username' => ':attribute无效.',
'uuid' => ':attribute无效.',
'landline-number' => ':attribute无效.',
'iran-plate' => ':attribute无效.',
];
33 changes: 33 additions & 0 deletions tests/Rules/ValidIranPlateTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Milwad\LaravelValidate\Tests\Rules;

use Milwad\LaravelValidate\Rules\ValidIranPlate;
use Milwad\LaravelValidate\Tests\TestCase;

class ValidIranPlateTest extends TestCase
{
/**
* Test iran license plate is valid.
*/
public function test_iran_plate_is_valid()
{
$rules = ['car_number' => [new ValidIranPlate]];
$data = ['car_number' => '32 ی 321 ایران 45'];
$passes = $this->app['validator']->make($data, $rules)->passes();

$this->assertTrue($passes);
}

/**
* Test iran license plate is not valid.
*/
public function test_iran_plate_is_not_valid()
{
$rules = ['car_number' => [new ValidIranPlate]];
$data = ['car_number' => '32 ی 321 ترکیه 45'];
$passes = $this->app['validator']->make($data, $rules)->passes();

$this->assertFalse($passes);
}
}