1. Go to this page and download the library: Download iamfarhad/validation library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
iamfarhad / validation example snippets
// Old way (still works)
'mobile' => ['ir_mobile']
// New modern way
'mobile' => [new Mobile()]
// Both approaches are supported!
use Iamfarhad\Validation\Rules\{NationalCode, Mobile, ShamsiDate};
// Validate Iranian user registration
$validator = Validator::make($request->all(), [
'first_name' => ['equired', new ShamsiDate()],
'company_id' => ['nullable', 'ir_company_id'],
]);
if ($validator->fails()) {
return response()->json(['errors' => $validator->errors()], 422);
}
use Illuminate\Support\Facades\Validator;
use Iamfarhad\Validation\Rules\{NationalCode, Mobile, ShamsiDate};
$validator = Validator::make($request->all(), [
'national_code' => ['
use Iamfarhad\Validation\Rules\Sheba;
// Iranian bank account numbers (IBAN format)
Validator::make(['account' => 'IR930150000001351800087201'], [
'account' => [new Sheba()]
]);
use Iamfarhad\Validation\Rules\Phone;
use Iamfarhad\Validation\Rules\PhoneArea;
// Landline numbers
Validator::make(['phone' => '22345678'], [
'phone' => [new Phone()]
]);
// With area code
Validator::make(['phone_area' => '02122345678'], [
'phone_area' => [new PhoneArea()]
]);
use Iamfarhad\Validation\Rules\CardNumber;
// Validates using Luhn algorithm
Validator::make(['card' => '4532015112830366'], [
'card' => [new CardNumber()]
]);
use Iamfarhad\Validation\Rules\PersianAlphaNum;
use Iamfarhad\Validation\Rules\PersianAlphaEngNum;
// Persian alphabet and Persian numbers
Validator::make(['text' => 'فارسی۱۲۳'], [
'text' => [new PersianAlphaNum()]
]);
// Persian alphabet and English numbers
Validator::make(['text' => 'فارسی123'], [
'text' => [new PersianAlphaEngNum()]
]);
use Iamfarhad\Validation\Rules\CompanyId;
// Iranian company identifier
Validator::make(['company_id' => '14007650912'], [
'company_id' => [new CompanyId()]
]);