Laravel Persian Validation provides validation for Persian alphabet, number and etc.
- Laravel 6.* | 8.x | 9.x
- PHP 7.3 | 7.4 | 8.0 | 8.1
Via Composer
$ composer require iamfarhad/validation
The package will automatically register itself.
If you wish to edit the package translations, you can run the following command to publish them into your resources/lang
folder
php artisan vendor:publish --provider="Iamfarhad\Validation\ValidationRulesServiceProvider"
You can run the tests with:
composer test
You can access to validation rules by passing the rules key according blew following table:
Rules | Descriptions |
---|---|
new PersianAlpha() | Persian alphabet |
new PersianNumber() | Persian numbers |
new Mobile() | Iran mobile numbers |
new Sheba() | Iran Sheba numbers |
new NationalCode() | Iran melli code |
new IsNotPersian() | Doesn't accept Persian alphabet and numbers |
new Mobile() | Iran mobile numbers |
new Phone() | Iran phone numbers |
new PhoneArea() | Iran phone numbers with area code |
new CardNumber() | Payment card numbers |
new Address() | Accept Persian, English and ... alphabet, Persian and English numbers and some special characters |
new PostalCode() | Iran postal code |
Accept Persian language alphabet according to standard Persian, this is the way you can use this validation rule:
Validator::make(
['name' => 'فارسی'],
['name' => [new PersianAlpha()]
);
Validate Persian standard numbers (۰۱۲۳۴۵۶۷۸۹):
Validator::make(
['num' => '۰۱۲۳۴۵۶۷۸۹'],
['num' => [new PersianNumber()]
);
Validate Iran mobile phones (irancel, rightel, hamrah-e-aval, ...):
Validator::make(
['mob' => '09127777777'],
['mob' => [new Mobile()]
);
Validate Iran bank sheba numbers:
Validator::make(
['sheba_number' => 'IR062960000000100324200001'],
['sheba_number' => [new Sheba()]
);
Validate Iran national code (melli-code):
Validator::make(
['codeMelli' => '3240175800'],
['codeMelli' => [new NationalCode()]
);
Validate Iran payment card numbers:
Validator::make(
['card' => '6274129005473742'],
['card' => [new CardNumber()]
);
Validate Iran postal code:
Validator::make(
['postal' => '16719735744'],
['postal' => [new PostalCode()]
);
// in a `FormRequest`
public function rules()
{
return [
'NationalCode' => ['required', new NationalCode()],
];
}
This component is developed by the following person(s)
Farhad Zand |
Please contribute in package completion. This is the best support.
The Laravel persian validation Module is open-sourced software licensed under the MIT license