Coder Social home page Coder Social logo

laravel-persian-validation's Introduction

Laravel Persian Validation

Laravel Persian Validation Provides validation for Persian alphabet, number and etc.

Requirement

  • Laravel 6, 7, 8, 9, 10, 11
  • PHP 7.4 , 8, 8.1, 8.2

Install

Via Composer

composer require sadegh19b/laravel-persian-validation

Publishing Language Files

To publish the language files for custom validation messages, execute the following command. This will place the file at resources/lang/{locale}/persian-validation.php.

php artisan vendor:publish --provider="Sadegh19b\LaravelPersianValidation\PersianValidationServiceProvider"

Usage

You can access to validation rules by passing the rules key according blew following table:

Rules Descriptions Acceptable Examples
persian_alpha Persian alphabet صادق
persian_num Persian numbers ۱۲۳۴
persian_alpha_num Persian alphabet and numbers صادق۱۲۳۴
persian_alpha_eng_num Persian alphabet and numbers with english numbers صادق۱۲34
persian_not_accept Doesn't accept Persian alphabet and numbers cant be persian
shamsi_date Check shamsi (jalali) date with format(Y/m/d) or format(Y-m-d) 1373/3/19
shamsi_date:persian Check shamsi (jalali) date with format(Y/m/d) or format(Y-m-d) with persian number ۱۳۷۳/۳/۱۹
shamsi_date_between:1300,1400 Check shamsi (jalali) date with format(Y/m/d) or format(Y-m-d) between years 1373/3/19
shamsi_date_between:1300,1400,persian Check shamsi (jalali) date with format(Y/m/d) or format(Y-m-d) between years with persian number ۱۳۷۳/۳/۱۹
ir_mobile Iranian mobile numbers 00989173456789, +989173456789, 989173456789, 09173456789, 91712345678
ir_mobile:zero_code Iranian mobile numbers with double zero country code 00989173456789
ir_mobile:plus Iranian mobile numbers with plus country code +989173456789
ir_mobile:code Iranian mobile numbers with country code 989173456789
ir_mobile:zero Iranian mobile numbers starts with zero 09173456789
ir_mobile:without_zero Iranian mobile numbers without first zero 9173456789
ir_phone Iranian phone numbers 37236445
ir_phone_code Iranian phone area code 077, 021, ...
ir_phone_with_code Iranian phone number with area code 07737236445
ir_postal_code Iranian postal code 1619735744, 16197-35744
ir_postal_code:seprate Iranian postal code sperated 16197-35744
ir_postal_code:without_seprate Iranian postal code without seprate 1619735744
ir_bank_card_number Iranian bank payment card numbers 6274129005473742
ir_bank_card_number:seprate Iranian bank payment card numbers seprate between digits with dash 6274-1290-0547-3742
ir_bank_card_number:space Iranian bank payment card numbers seprate between digits with space 6274 1290 0547 3742
ir_sheba Iranian Sheba numbers IR062960000000100324200001
ir_national_code Iran melli code 0013542419
a_url Check correct URL http://google.com, https://www.google.com
a_domain Check correct Domain www.google.com, google.com
ir_company_id Iranian National Legal Entity Identifier (Shenase Melli Ashkhas Hoghoghi) 14007650912

Persian Alpha

Accept Persian language alphabet according to standard Persian, this is the way you can use this validation rule:

$input = [ 'فارسی' ];

$rules = [ 'persian_alpha' ];

Validator::make( $input, $rules );

Persian numbers

Validate Persian standard numbers (۰۱۲۳۴۵۶۷۸۹):

$input = [ '۰۱۲۳۴۵۶۷۸۹' ];

$rules = [ 'persian_num' ];

Validator::make( $input, $rules );

Persian Alpha Num

Validate Persian alpha num:

$input = [ '۰فارسی۱۲۳۴۵۶۷۸۹' ];

$rules = [ 'persian_alpha_num' ];

Validator::make( $input, $rules );

Persian Alpha Eng Num

Validate Persian alpha num with english num:

$input = [ '۰فارسی۱۲۳۴۵6789' ];

$rules = [ 'persian_alpha_eng_num' ];

Validator::make( $input, $rules );

Shamsi Date

Validate shamsi (jalali) date:

$input = [ '1373/3/19' ];

$rules = [ 'shamsi_date' ];

Validator::make( $input, $rules );

Shamsi Date Between

Validate shamsi (jalali) date between years:

$input = [ '1373/3/19' ];

$rules = [ 'shamsi_date_between:1300,1400' ];

Validator::make( $input, $rules );

Iran mobile phone

Validate Iranian mobile numbers (Irancell, Rightel, Hamrah-e-aval, ...):

$input = [ '09381234567' ];

$rules = [ 'ir_mobile' ];

Validator::make( $input, $rules );

Sheba number

Validate Iranian bank sheba numbers:

$input = [ 'IR062960000000100324200001' ];

$rules = [ 'ir_sheba' ];

Validator::make( $input, $rules );

Iran national code

Validate Iranian national code (Melli Code):

$input = [ '3240175800' ];

$rules = [ 'ir_national_code' ];

Validator::make( $input, $rules );

Payment card number

Validate Iranian bank payment card numbers:

$input = [ '6274129005473742' ];

$rules = [ 'ir_bank_card_number' ];

Validator::make( $input, $rules );

Iran postal code

Validate Iranian postal code:

$input = [ '167197-35744' ];

$rules = [ 'ir_postal_code' ];

Validator::make( $input, $rules );

or

$input = [ '16719735744' ];

$rules = [ 'ir_postal_code' ];

Validator::make( $input, $rules );

Iran company id

Validate Iranian National Legal Entity Identifier (Shenase Melli Ashkhas Hoghoghi)

$input = [ '14007650912' ];

$rules = [ 'ir_company_id' ];

Validator::make( $input, $rules );

More

Full list of Persian Validation rules usage:

Validator::make( $request->all(), [

  'name'          => 'persian_alpha|unique|max:25', // Validate Persian alphabet, unique and max to 25 characters

  'age'           => 'persian_num|required',  // Validate Persian numbers and check it's required

  'city'          => 'persian_alpha_num|min:10',  // Validate persian alphabet & numbers at least 10 digit accepted

  'address'       => 'persian_alpha_eng_num',  // Validate persian alphabet & numbers with english numbers

  'birthday'      => 'shamsi_date', // Validate shamsi date 

  'start_date'    => 'shamsi_date_between:1300,1400', // Validate shamsi date between years

  'mobile'        => 'ir_mobile', // Validate mobile number

  'sheba_number'  => 'ir_sheba', // Validate sheba number of bank account

  'melli_code'    => 'ir_national_code',  // Validate melli code number

  'latin_name'    => 'persian_not_accept',  // Validate alphabet and doesn't contain Persian alphabet or number

  'url'           => 'a_url', // Validate url

  'domain'        => 'a_domain',  // Validate domain

  'phone'         => 'ir_phone', // Validate phone number
  
  'area_code'     => 'ir_phone_code', // Validate phone area code
  
  'phone_code'    => 'ir_phone_with_code', // Validate phone number with area code

  'card_number'   => 'ir_bank_card_number', // Validate payment card number

  'postal_code'   => 'ir_postal_code' // validate iran postal code format
  
  'company_id'    => 'ir_company_id',  // Iranian National Legal Entity Identifier (Shenase Melli Ashkhas Hoghoghi)

]);

License

The MIT license (MIT). Please see License File for more information.

laravel-persian-validation's People

Contributors

ahbanavi avatar alirezasedghi avatar amirfallahii avatar hasanmonfared avatar hossein-zare avatar mojtabarks avatar mra-dev avatar sadegh19b avatar taha-moghaddam avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

laravel-persian-validation's Issues

Error in postal code validation

Hi,
Unfortunately, the existing regex code that you used for the postal code does not work in some cases.
For example, 5951412749

How can I apply a date limit?

Hi dear Sadegh.
For example, for the birth date field, it should be prevented that the date is selected from the future. Or as another example, the date of death must be after the date of birth.
Tanks a lot.

Validation doesn't work

if you put the "1234-3523-2523-2534" as a bank card number and "ir_bank_card_number:seprate" as validation rule, it always returns false.

the same thing happens for other rules like ir_sheba, ...

IR-National code error when input is integer

Hi
With LaravelExcel package when you try to use ir_national_code validator, the input value for validateIranianNationalCode method in PersianValidators.php is integer, so line 378 throws with an exception of: Trying to access array offset on value of type int.

Please add string cast for $value input in method to avoid this error.

Thank you for helpful package.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.