├── .gitignore ├── .travis.yml ├── LICENSE.md ├── _config.yml ├── composer.json ├── lang ├── en.php └── fa.php ├── phpunit.xml ├── readme.md ├── src ├── Config.php ├── PersianValidationServiceProvider.php ├── ValidationMessages.php └── ValidationRules.php └── tests └── PersianValidationTest.php /.gitignore: -------------------------------------------------------------------------------- 1 | vendor/ 2 | composer.lock 3 | phpunit.phar 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | dist: trusty 4 | 5 | php: 6 | - 5.6 7 | - 7.0 8 | - 7.1 9 | - 7.2 10 | - 7.3 11 | 12 | install: composer update 13 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-architect -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "anetwork/validation", 3 | "license": "MIT", 4 | "description": "Laravel persian validation", 5 | "keyword": ["laravel", "validation", "persian", "farsi", "validate", "lumen", "check"], 6 | "authors": [ 7 | { 8 | "name": "Shahrokh Niakan", 9 | "email": "shahrokhniakan@gmail.com" 10 | } 11 | ], 12 | "extra": { 13 | "laravel": { 14 | "providers": [ 15 | "Anetwork\\Validation\\PersianValidationServiceProvider" 16 | ] 17 | } 18 | }, 19 | "autoload": { 20 | "psr-4": { 21 | "Anetwork\\Validation\\": "src" 22 | } 23 | }, 24 | "require-dev": { 25 | "phpunit/phpunit": "5.6.3" 26 | }, 27 | "require": { 28 | "illuminate/support": ">=5.2" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /lang/en.php: -------------------------------------------------------------------------------- 1 | 'must be a persian alpahbet.', 6 | 'persian_num' => 'must be a persian number.', 7 | 'persian_alpha_num' => 'must be a persian alpahbet or number.', 8 | 'iran_mobile' => 'must be a iran mobile number.', 9 | 'sheba' => 'must be a sheba number.', 10 | 'melli_code' => 'must be a iran melli code.', 11 | 'is_not_persian' => 'could not be contain persian alpahbet or number.', 12 | 'limited_array' => 'must ba a array and contain values you define not more.', 13 | 'unsigned_num' => 'must be an unsigned number.', 14 | 'alpha_space' => 'must be alphabet and space.', 15 | 'a_url' => 'url is not correct.', 16 | 'a_domain' => 'domain is not correct.', 17 | 'more' => 'must be more than parameter.', 18 | 'less' => 'must be less than parameter.', 19 | 'iran_phone' => 'must be a iran phone number.', 20 | 'iran_phonewith_area_code' => 'must be a iran phone number.', 21 | 'card_number' => 'must be a valid payment card number.', 22 | 'address' => 'must be a correct address.', 23 | 'iran_postal_code' => 'must be a iran postal code.', 24 | 'package_name' => 'must be a valid package name.' 25 | 26 | ]; 27 | -------------------------------------------------------------------------------- /lang/fa.php: -------------------------------------------------------------------------------- 1 | 'حروف وارد شده باید فارسی باشد.', 6 | 'persian_num' => 'عدد وارد شده باید فارسی باشد.', 7 | 'persian_alpha_num' => 'حروف و عدد وارد شده باید فارسی باشد.', 8 | 'iran_mobile' => 'شماره همراه قابل قبول نیست.', 9 | 'sheba' => 'شماره شبا قابل قبول نیست.', 10 | 'melli_code' => 'کد ملی قابل قبول نیست.', 11 | 'is_not_persian' => 'حروف غیر لاتین قابل قبول نیست.', 12 | 'limited_array' => 'فيلد مورد نظر قبل قبول نيست.', 13 | 'unsigned_num' => 'عدد مورد نظر قابل قبول نیست.', 14 | 'alpha_space' => 'باید شامل حروف و فاصله باشد.', 15 | 'a_url' => 'آدرس قابل قبول نیست.', 16 | 'a_domain' => 'دامنه قابل قبول نیست.', 17 | 'more' => 'فیلد باید بزرگتر باشد.', 18 | 'less' => 'فیلد باید کوچیکتر باشد.', 19 | 'iran_phone' => 'شماره تلفن قابل قبول نیست.', 20 | 'iran_phone_with_area_code' => 'شماره تلفن قابل قبول نیست.', 21 | 'card_number' => 'شماره کارت قابل قبول نیست.', 22 | 'address' => 'آدرس وارد شده قابل قبول نیست.', 23 | 'iran_postal_code' => 'کدپستی وارد شده قابل قبول نیست.', 24 | 'package_name' => 'نام پکیج صحیح نیست.' 25 | 26 | ]; 27 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 24 | 25 | 26 | 27 | tests 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/opencafe/validation.svg?branch=master)](https://travis-ci.org/opencafe/validation) 2 | [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/opencafe/validation/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/anetwork/validation/?branch=master) 3 | [![Latest Stable Version](https://poser.pugx.org/anetwork/validation/v/stable)](https://packagist.org/packages/anetwork/validation) 4 | [![Total Downloads](https://poser.pugx.org/anetwork/validation/downloads)](https://packagist.org/packages/anetwork/validation) 5 | [![License](https://poser.pugx.org/anetwork/validation/license)](https://github.com/anetwork/validation/blob/master/LICENSE.md) 6 | 7 | # Laravel Persian Validation 8 | 9 | Laravel Persian Validation provides validation for Persian alphabet, number and etc. 10 | 11 | ## Requirement 12 | 13 | * Laravel 5.* 14 | * PHP 5.6-7.3 15 | 16 | ## License 17 | 18 | Laravel Persian Validation is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT) 19 | 20 | ## Install 21 | 22 | Via Composer 23 | 24 | ``` bash 25 | $ composer require Anetwork/Validation 26 | ``` 27 | 28 | ## Config 29 | 30 | Add the following provider to providers part of config/app.php 31 | ``` php 32 | Anetwork\Validation\PersianValidationServiceProvider::class 33 | ``` 34 | 35 | ## vendor:publish 36 | You can run vendor:publish command to have custom lang file of package on this path ( resources/lang/validation ) 37 | 38 | ## Usage 39 | 40 | You can access to validation rules by passing the rules key according blew following table: 41 | 42 | | Rules | Descriptions | 43 | | --- | --- | 44 | | persian_alpha | Persian alphabet | 45 | | persian_num | Persian numbers | 46 | | persian_alpha_num | Persian alphabet and numbers | 47 | | iran_mobile | Iran mobile numbers | 48 | | sheba | Iran Sheba numbers | 49 | | melli_code | Iran melli code | 50 | | is_not_persian | Doesn't accept Persian alphabet and numbers | 51 | | limited_array | Check variable is array and array must be lesser and equal than parameter | 52 | | unsigned_num | Check variable is unsigned numbers | 53 | | alpha_space | Accept Persian, English and ... alphabet, space character| 54 | | a_url | Check correct URL | 55 | | a_domain | Check correct Domain | 56 | | more | Check value be max and not equal too| 57 | | less | Check value be min and not equal too | 58 | | iran_phone | Iran phone numbers | 59 | | card_number | Payment card numbers | 60 | | address | Accept Persian, English and ... alphabet, Persian and English numbers and some special characters| 61 | | iran_postal_code | Iran postal code | 62 | | package_name | Check APK package name | 63 | 64 | 65 | ### Persian Alpha 66 | Accept Persian language alphabet according to standard Persian, this is the way you can use this validation rule: 67 | 68 | ``` 69 | $input = [ 'فارسی' ]; 70 | 71 | $rules = [ 'persian_alpha' ]; 72 | 73 | Validator::make( $input, $rules ); 74 | ``` 75 | 76 | ### Persian numbers 77 | Validate Persian standard numbers (۰۱۲۳۴۵۶۷۸۹): 78 | 79 | ``` 80 | $input = [ '۰۱۲۳۴۵۶۷۸۹' ]; 81 | 82 | $rules = [ 'persian_num' ]; 83 | 84 | Validator::make( $input, $rules ); 85 | ``` 86 | 87 | ### Persian Alpha Num 88 | Validate Persian alpha num: 89 | 90 | ``` 91 | $input = [ 'فارسی۱۲۳۴۵۶۷۸۹' ]; 92 | 93 | $rules = [ 'persian_alpha_num' ]; 94 | 95 | Validator::make( $input, $rules ); 96 | ``` 97 | 98 | ### Iran mobile phone 99 | Validate Iran mobile phones (irancel, rightel, hamrah-e-aval, ...): 100 | 101 | ``` 102 | $input = [ '09381234567' ]; 103 | 104 | $rules = [ 'iran_mobile' ]; 105 | 106 | Validator::make( $input, $rules ); 107 | ``` 108 | 109 | ### Sheba number 110 | Validate Iran bank sheba numbers: 111 | 112 | ``` 113 | $input = [ 'IR062960000000100324200001' ]; 114 | 115 | $rules = [ 'sheba' ]; 116 | 117 | Validator::make( $input, $rules ); 118 | ``` 119 | 120 | ### Iran national code 121 | Validate Iran national code (melli-code): 122 | 123 | ``` 124 | $input = [ '3240175800' ]; 125 | 126 | $rules = [ 'melli_code' ]; 127 | 128 | Validator::make( $input, $rules ); 129 | ``` 130 | 131 | ### Payment card number 132 | Validate Iran payment card numbers: 133 | 134 | ``` 135 | $input = [ '6274129005473742' ]; 136 | 137 | $rules = [ 'card_number' ]; 138 | 139 | Validator::make( $input, $rules ); 140 | ``` 141 | 142 | ### Iran postal code 143 | Validate Iran postal code: 144 | 145 | ``` 146 | $input = [ '167197-35744' ]; 147 | 148 | $rules = [ 'iran_postal_code' ]; 149 | 150 | Validator::make( $input, $rules ); 151 | 152 | 153 | $input = [ '16719735744' ]; 154 | 155 | $rules = [ 'iran_postal_code' ]; 156 | 157 | Validator::make( $input, $rules ); 158 | 159 | ``` 160 | 161 | ## More 162 | Here is full list of Anetwork validation rules usage: 163 | 164 | ``` php 165 | Validator::make( $request->all(), [ 166 | 167 | 'name' => 'persian_alpha|unique|max:25', // Validate Persian alphabet, unique and max to 25 characters 168 | 169 | 'age' => 'persian_num|required', // Validate Persian numbers and check it's required 170 | 171 | 'city' => 'persian_alpha_num|min:10', // Validate persian alphabet & numbers at least 10 digit accepted 172 | 173 | 'mobile' => 'iran_mobile', // Validate mobile number 174 | 175 | 'sheba_number' => 'sheba', // Validate sheba number of bank account 176 | 177 | 'melli_code' => 'melli_code', // Validate melli code number 178 | 179 | 'latin_name' => 'is_not_persian', // Validate alphabet and doesn't contain Persian alphabet or number 180 | 181 | 'your_array' => 'limited_array:2', // Validate your array variable and must be contian 2 member or lesser 182 | 183 | 'url' => 'a_url', // Validate url 184 | 185 | 'domain' => 'a_domain', // Validate domain 186 | 187 | 'more' => 'more:10', // Validate value be more than parameter 188 | 189 | 'less' => 'less:10', // Validate value be less than parameter 190 | 191 | 'phone' => 'iran_phone', // Validate phone number 192 | 193 | 'card_number' => 'card_number', // Validate payment card number 194 | 195 | 'address' => 'address' // validate Persian, English and ... alphabet, Persian and English numbers and some special characters 196 | 197 | 'postal_code' => 'iran_postal_code' // validate iran postal code format 198 | 199 | 'package_name' => 'package_name' // validate APK package name 200 | 201 | 202 | ]); 203 | ``` 204 | 205 | -------------------------------------------------------------------------------- /src/Config.php: -------------------------------------------------------------------------------- 1 | 5.3, 5 | ]; -------------------------------------------------------------------------------- /src/PersianValidationServiceProvider.php: -------------------------------------------------------------------------------- 1 | 11 | * @since May 25, 2016 12 | */ 13 | class PersianValidationServiceProvider extends ServiceProvider 14 | { 15 | 16 | /** 17 | * @var array 18 | */ 19 | private $validationRules = [ 20 | 'persian_alpha' => 'Alpha', 21 | 'persian_num' => 'Num', 22 | 'persian_alpha_num' => 'AlphaNum', 23 | 'iran_mobile' => 'IranMobile', 24 | 'sheba' => 'Sheba', 25 | 'melli_code' => 'MelliCode', 26 | 'is_not_persian' => 'IsNotPersian', 27 | 'limited_array' => 'LimitedArray', 28 | 'unsigned_num' => 'UnSignedNum', 29 | 'alpha_space' => 'AlphaSpace', 30 | 'a_url' => 'Url', 31 | 'a_domain' => 'Domain', 32 | 'more' => 'More', 33 | 'less' => 'Less', 34 | 'iran_phone' => 'IranPhone', 35 | 'iran_phone_with_area_code' => 'IranPhoneWithAreaCode', 36 | 'card_number' => 'CardNumber', 37 | 'address' => 'Address', 38 | 'iran_postal_code' => 'IranPostalCode', 39 | 'package_name' => 'PackageName', 40 | ]; 41 | 42 | /** 43 | * create custom validation rules and messages 44 | * @author Shahrokh Niakan 45 | * @since May 25, 2016 46 | * @return void 47 | */ 48 | public function boot() 49 | { 50 | // publish lang file to resources/lang/validation 51 | $this->publishes([ 52 | __DIR__ . '/../lang/' . App::getLocale() . '.php' => resource_path('lang/validation/' . App::getLocale() . '.php'), 53 | ]); 54 | 55 | foreach($this->validationRules as $name => $method) 56 | { 57 | Validator::extend($name, 'ValidationRules@'.$method); 58 | 59 | Validator::replacer($name, 'ValidationMessages@Msg'); 60 | } 61 | 62 | } 63 | 64 | /** 65 | * register PersianValidation service 66 | * @author Shahrokh Niakan 67 | * @since May 31, 2016 68 | * @return void 69 | */ 70 | public function register() 71 | { 72 | $this->app->bind('ValidationRules', 'Anetwork\Validation\ValidationRules'); 73 | 74 | $this->app->bind('ValidationMessages', 'Anetwork\Validation\ValidationMessages'); 75 | 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/ValidationMessages.php: -------------------------------------------------------------------------------- 1 | 8 | * @since Sep 11, 2016 9 | */ 10 | class ValidationMessages 11 | { 12 | /** 13 | * @var string 14 | */ 15 | protected $lang; 16 | 17 | /** 18 | * @var array 19 | */ 20 | protected $config; 21 | 22 | /** 23 | * @var array 24 | */ 25 | protected static $messages; 26 | 27 | /** 28 | * @var array 29 | */ 30 | protected static $app; 31 | 32 | /** 33 | * @author Shahrokh Niakan 34 | * @since Sep 21, 2016 35 | */ 36 | public function __construct() 37 | { 38 | $this->lang = App::getLocale(); 39 | 40 | if(! file_exists(resource_path('lang/validation/' . $this->lang . '.php'))){ 41 | $this->config = include __DIR__ . '/../lang/' . $this->lang . '.php'; 42 | } else { 43 | $this->config = include resource_path('lang/validation/' . $this->lang . '.php'); 44 | } 45 | } 46 | 47 | /** 48 | * set user custom messeages 49 | * @param $validator 50 | * @author Shahrokh Niakan 51 | * @since Jun 6, 2017 52 | */ 53 | public static function setCustomMessages( $validator ) 54 | { 55 | self::$app = include __DIR__ . '/Config.php'; 56 | 57 | if ( $validator ) { 58 | if ( round(floatval(App::version()), 1) > self::$app['version'] ) { 59 | self::$messages = $validator->customMessages; 60 | } else { 61 | self::$messages = $validator->getCustomMessages(); 62 | } 63 | } 64 | } 65 | 66 | /** 67 | * get validations message 68 | * @param $message 69 | * @param $attribute 70 | * @param $rule 71 | * @author Shahrokh Niakan 72 | * @since Jun 10, 2017 73 | * @return string 74 | */ 75 | public function Msg($message, $attribute, $rule) 76 | { 77 | if ( isset( self::$messages[$rule] ) ) { 78 | return str_replace($message, self::$messages[$rule], $message); 79 | } 80 | 81 | return str_replace($message, $this->config[ $rule ], $message); 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /src/ValidationRules.php: -------------------------------------------------------------------------------- 1 | 8 | * @since May 21, 2016 9 | */ 10 | class ValidationRules 11 | { 12 | /** 13 | * @var boolean 14 | */ 15 | protected $status; 16 | 17 | /** 18 | * validate persian alphabet and space 19 | * @param $attribute 20 | * @param $value 21 | * @param $parameters 22 | * @param $validator 23 | * @author Shahrokh Niakan 24 | * @since May 21, 2016 25 | * @return boolean 26 | */ 27 | public function Alpha($attribute, $value, $parameters, $validator) 28 | { 29 | ValidationMessages::setCustomMessages( $validator ); 30 | 31 | $this->status = (bool) preg_match("/^[\x{600}-\x{6FF}\x{200c}\x{064b}\x{064d}\x{064c}\x{064e}\x{064f}\x{0650}\x{0651}\s]+$/u", $value); 32 | 33 | return $this->status ; 34 | 35 | } 36 | 37 | /** 38 | * validate persian number 39 | * @param $attribute 40 | * @param $value 41 | * @param $parameters 42 | * @param $validator 43 | * @author Shahrokh Niakan 44 | * @since May 21, 2016 45 | * @return boolean 46 | */ 47 | public function Num($attribute, $value, $parameters, $validator) 48 | { 49 | ValidationMessages::setCustomMessages( $validator ); 50 | 51 | $this->status = (bool) preg_match('/^[\x{6F0}-\x{6F9}]+$/u', $value); 52 | 53 | return $this->status ; 54 | } 55 | 56 | /** 57 | * validate persian alphabet, number and space 58 | * @param $attribute 59 | * @param $value 60 | * @param $parameters 61 | * @param $validator 62 | * @author Shahrokh Niakan 63 | * @since May 21, 2016 64 | * @return boolean 65 | */ 66 | public function AlphaNum($attribute, $value, $parameters, $validator) 67 | { 68 | ValidationMessages::setCustomMessages( $validator ); 69 | 70 | $this->status = (bool) preg_match('/^[\x{600}-\x{6FF}\x{200c}\x{064b}\x{064d}\x{064c}\x{064e}\x{064f}\x{0650}\x{0651}\s]+$/u', $value); 71 | 72 | return $this->status; 73 | } 74 | 75 | /** 76 | * validate mobile number 77 | * @param $attribute 78 | * @param $value 79 | * @param $parameters 80 | * @param $validator 81 | * @author Shahrokh Niakan 82 | * @since May 21, 2016 83 | * @return boolean 84 | */ 85 | public function IranMobile($attribute, $value, $parameters, $validator) 86 | { 87 | ValidationMessages::setCustomMessages( $validator ); 88 | 89 | if ((bool) preg_match('/^(((98)|(\+98)|(0098)|0)(9){1}[0-9]{9})+$/', $value) || (bool) preg_match('/^(9){1}[0-9]{9}+$/', $value)) 90 | return true; 91 | 92 | return false; 93 | } 94 | 95 | /** 96 | * validate sheba number 97 | * @param $attribute 98 | * @param $value 99 | * @param $parameters 100 | * @param $validator 101 | * @author Shahrokh Niakan 102 | * @since May 21, 2016 103 | * @return boolean 104 | */ 105 | public function Sheba($attribute, $value, $parameters, $validator) 106 | { 107 | ValidationMessages::setCustomMessages( $validator ); 108 | 109 | $ibanReplaceValues = array(); 110 | 111 | if (!empty($value)) { 112 | $value = preg_replace('/[\W_]+/', '', strtoupper($value)); 113 | 114 | if (( 4 > strlen($value) || strlen($value) > 34 ) || ( is_numeric($value [ 0 ]) || is_numeric($value [ 1 ]) ) || ( ! is_numeric($value [ 2 ]) || ! is_numeric($value [ 3 ]) )) { 115 | return false; 116 | } 117 | 118 | $ibanReplaceChars = range('A', 'Z'); 119 | 120 | foreach (range(10, 35) as $tempvalue) { 121 | $ibanReplaceValues[] = strval($tempvalue); 122 | } 123 | 124 | 125 | $tmpIBAN = substr($value, 4) . substr($value, 0, 4); 126 | 127 | $tmpIBAN = str_replace($ibanReplaceChars, $ibanReplaceValues, $tmpIBAN); 128 | 129 | $tmpValue = intval(substr($tmpIBAN, 0, 1)); 130 | 131 | for ($i = 1; $i < strlen($tmpIBAN); $i++) { 132 | $tmpValue *= 10; 133 | 134 | $tmpValue += intval(substr($tmpIBAN, $i, 1)); 135 | 136 | $tmpValue %= 97; 137 | } 138 | 139 | if ($tmpValue != 1) { 140 | return false; 141 | } 142 | 143 | return true; 144 | } 145 | 146 | return false; 147 | } 148 | 149 | /** 150 | * validate meliCode number 151 | * @param $attribute 152 | * @param $value 153 | * @param $parameters 154 | * @param $validator 155 | * @author Shahrokh Niakan 156 | * @since May 21, 2016 157 | * @return boolean 158 | */ 159 | public function MelliCode($attribute, $value, $parameters, $validator) 160 | { 161 | ValidationMessages::setCustomMessages( $validator ); 162 | 163 | if (!preg_match('/^\d{8,10}$/', $value) || preg_match('/^[0]{10}|[1]{10}|[2]{10}|[3]{10}|[4]{10}|[5]{10}|[6]{10}|[7]{10}|[8]{10}|[9]{10}$/', $value)) { 164 | return false; 165 | } 166 | 167 | $sub = 0; 168 | 169 | if (strlen($value) == 8) { 170 | $value = '00' . $value; 171 | } elseif (strlen($value) == 9) { 172 | $value = '0' . $value; 173 | } 174 | 175 | for ($i = 0; $i <= 8; $i++) { 176 | $sub = $sub + ( $value[$i] * ( 10 - $i ) ); 177 | } 178 | 179 | if (( $sub % 11 ) < 2) { 180 | $control = ( $sub % 11 ); 181 | } else { 182 | $control = 11 - ( $sub % 11 ); 183 | } 184 | 185 | if ($value[9] == $control) { 186 | return true; 187 | } else { 188 | return false; 189 | } 190 | 191 | } 192 | 193 | /** 194 | * validate string that is not contain persian alphabet and number 195 | * @param $attribute 196 | * @param $value 197 | * @param $parameters 198 | * @param $validator 199 | * @author Shahrokh Niakan 200 | * @since June 13, 2016 201 | * @return boolean 202 | */ 203 | public function IsNotPersian($attribute, $value, $parameters, $validator) 204 | { 205 | ValidationMessages::setCustomMessages( $validator ); 206 | 207 | if (is_string($value)) { 208 | 209 | $this->status = (bool) preg_match("/[\x{600}-\x{6FF}]/u", $value); 210 | 211 | return !$this->status; 212 | 213 | } 214 | 215 | return false; 216 | } 217 | 218 | /** 219 | * validate array with custom count of array 220 | * @param $attribute 221 | * @param $value 222 | * @param $parameters 223 | * @param $validator 224 | * @author Shahrokh Niakan 225 | * @since June 13, 2016 226 | * @return boolean 227 | */ 228 | public function LimitedArray($attribute, $value, $parameters, $validator) 229 | { 230 | ValidationMessages::setCustomMessages( $validator ); 231 | 232 | if (is_array($value)) { 233 | 234 | if (isset($parameters[0])) { 235 | 236 | return ( (count($value) <= $parameters[0]) ? true : false ); 237 | 238 | } else { 239 | 240 | return true; 241 | 242 | } 243 | 244 | } 245 | 246 | return false; 247 | } 248 | 249 | /** 250 | * validate number to be unsigned 251 | * @param $attribute 252 | * @param $value 253 | * @param $parameters 254 | * @param $validator 255 | * @author Shahrokh Niakan 256 | * @since July 22, 2016 257 | * @return boolean 258 | */ 259 | public function UnSignedNum($attribute, $value, $parameters, $validator) 260 | { 261 | ValidationMessages::setCustomMessages( $validator ); 262 | 263 | $this->status = (bool) preg_match('/^\d+$/', $value); 264 | 265 | return $this->status; 266 | } 267 | 268 | /** 269 | * validate alphabet and spaces 270 | * @param $attribute 271 | * @param $value 272 | * @param $parameters 273 | * @param $validator 274 | * @author Shahrokh Niakan 275 | * @since Agu 3, 2016 276 | * @return boolean 277 | */ 278 | public function AlphaSpace($attribute, $value, $parameters, $validator) 279 | { 280 | ValidationMessages::setCustomMessages( $validator ); 281 | 282 | $this->status = (bool) preg_match("/^[\pL\s\x{200c}\x{064b}\x{064d}\x{064c}\x{064e}\x{064f}\x{0650}\x{0651}]+$/u", $value); 283 | 284 | return $this->status; 285 | } 286 | 287 | /** 288 | * validate Url 289 | * @param $attribute 290 | * @param $value 291 | * @param $parameters 292 | * @param $validator 293 | * @author Shahrokh Niakan 294 | * @since Agu 17, 2016 295 | * @return boolean 296 | */ 297 | public function Url($attribute, $value, $parameters, $validator) 298 | { 299 | ValidationMessages::setCustomMessages( $validator ); 300 | 301 | $this->status = (bool) preg_match("/^(HTTP|http(s)?:\/\/(www\.)?[A-Za-z0-9]+([\-\.]{1,2}[A-Za-z0-9]+)*\.[A-Za-z]{2,40}(:[0-9]{1,40})?(\/.*)?)$/", $value); 302 | 303 | return $this->status; 304 | } 305 | 306 | /** 307 | * validate Domain 308 | * @param $attribute 309 | * @param $value 310 | * @param $parameters 311 | * @param $validator 312 | * @author Shahrokh Niakan 313 | * @since Agu 17, 2016 314 | * @return boolean 315 | */ 316 | public function Domain($attribute, $value, $parameters, $validator) 317 | { 318 | ValidationMessages::setCustomMessages( $validator ); 319 | 320 | $this->status = (bool) preg_match("/^((www\.)?(\*\.)?[A-Za-z0-9]+([\-\.]{1,2}[A-Za-z0-9]+)*\.[A-Za-z]{2,40}(:[0-9]{1,40})?(\/.*)?)$/", $value); 321 | 322 | return $this->status; 323 | } 324 | 325 | /** 326 | * value must be more than parameters 327 | * @param $attribute 328 | * @param $value 329 | * @param $parameters 330 | * @param $validator 331 | * @author Shahrokh Niakan 332 | * @since Agu 24, 2016 333 | * @return boolean 334 | */ 335 | public function More($attribute, $value, $parameters, $validator) 336 | { 337 | ValidationMessages::setCustomMessages( $validator ); 338 | 339 | if ( isset( $parameters[0] ) ) { 340 | 341 | return ( $value > $parameters[0] ? true : false ); 342 | 343 | } 344 | 345 | return false; 346 | } 347 | 348 | /** 349 | * value must be less than parameters 350 | * @param $attribute 351 | * @param $value 352 | * @param $parameters 353 | * @param $validator 354 | * @author Shahrokh Niakan 355 | * @since Agu 24, 2016 356 | * @return boolean 357 | */ 358 | public function Less($attribute, $value, $parameters, $validator) 359 | { 360 | ValidationMessages::setCustomMessages( $validator ); 361 | 362 | if ( isset( $parameters[0] ) ) { 363 | 364 | return ( $value < $parameters[0] ? true : false ); 365 | 366 | } 367 | 368 | return false; 369 | } 370 | 371 | /** 372 | * iran phone number 373 | * @param $attribute 374 | * @param $value 375 | * @param $parameters 376 | * @param $validator 377 | * @author Shahrokh Niakan 378 | * @since Agu 24, 2016 379 | * @return boolean 380 | */ 381 | public function IranPhone($attribute, $value, $parameters, $validator) 382 | { 383 | ValidationMessages::setCustomMessages( $validator ); 384 | 385 | $this->status = (bool) preg_match('/^[2-9][0-9]{7}+$/', $value) ; 386 | 387 | return $this->status; 388 | } 389 | 390 | /** 391 | * iran phone number with area code 392 | * @param $attribute 393 | * @param $value 394 | * @param $parameters 395 | * @param $validator 396 | * @author Amir Hosseini 397 | * @since Jan 28, 2019 398 | * @return boolean 399 | */ 400 | public function IranPhoneWithAreaCode($attribute, $value, $parameters, $validator) 401 | { 402 | ValidationMessages::setCustomMessages( $validator ); 403 | 404 | $this->status = (bool) preg_match('/^(0[1-9]{2})[2-9][0-9]{7}+$/', $value) ; 405 | 406 | return $this->status; 407 | } 408 | 409 | /** 410 | * payment card number validation 411 | * depending on 'http://www.aliarash.com/article/creditcart/credit-debit-cart.htm' article 412 | * 413 | * @param $attribute 414 | * @param $value 415 | * @param $parameters 416 | * @param $validator 417 | * @author Mojtaba Anisi 418 | * @since Oct 1, 2016 419 | * @return boolean 420 | */ 421 | function CardNumber($attribute, $value, $parameters, $validator) 422 | { 423 | ValidationMessages::setCustomMessages( $validator ); 424 | 425 | if (!preg_match('/^\d{16}$/', $value)) { 426 | return false; 427 | } 428 | 429 | $sum = 0; 430 | 431 | for ($position = 1; $position <= 16; $position++){ 432 | $temp = $value[$position - 1]; 433 | $temp = $position % 2 === 0 ? $temp : $temp * 2; 434 | $temp = $temp > 9 ? $temp - 9 : $temp; 435 | 436 | $sum += $temp; 437 | } 438 | 439 | return (bool)($sum % 10 === 0); 440 | } 441 | 442 | /** 443 | * validate alphabet, number and some special characters 444 | * @param $attribute 445 | * @param $value 446 | * @param $parameters 447 | * @param $validator 448 | * @author Shahrokh Niakan 449 | * @since Oct 7, 2016 450 | * @return boolean 451 | */ 452 | public function Address($attribute, $value, $parameters, $validator) 453 | { 454 | ValidationMessages::setCustomMessages( $validator ); 455 | 456 | $this->status = (bool) preg_match("/^[\pL\s\d\-\/\,\،\.\\\\\x{200c}\x{064b}\x{064d}\x{064c}\x{064e}\x{064f}\x{0650}\x{0651}\x{6F0}-\x{6F9}]+$/u", $value); 457 | 458 | return $this->status; 459 | } 460 | 461 | /** 462 | * validate Iran postal code format 463 | * @param $attribute 464 | * @param $value 465 | * @param $parameters 466 | * @param $validator 467 | * @author Shahrokh Niakan 468 | * @since Apr 5, 2017 469 | * @return boolean 470 | */ 471 | public function IranPostalCode($attribute, $value, $parameters, $validator) 472 | { 473 | ValidationMessages::setCustomMessages( $validator ); 474 | 475 | $this->status = (bool) preg_match("/^(\d{5}-?\d{5})$/", $value); 476 | 477 | return $this->status; 478 | } 479 | 480 | /** 481 | * validate package name of apk 482 | * @param $attribute 483 | * @param $value 484 | * @author Shahrokh Niakan 485 | * @since May 31, 2017 486 | * @return boolean 487 | */ 488 | public function PackageName($attribute, $value, $parameters, $validator) 489 | { 490 | ValidationMessages::setCustomMessages( $validator ); 491 | 492 | $this->status = (bool) preg_match("/^([a-zA-Z]{1}[a-zA-Z\d_]*\.)+[a-zA-Z][a-zA-Z\d_]*$/", $value); 493 | 494 | return $this->status; 495 | } 496 | 497 | } 498 | -------------------------------------------------------------------------------- /tests/PersianValidationTest.php: -------------------------------------------------------------------------------- 1 | 8 | * @since May 28, 2016 9 | */ 10 | class PersianValidationTest extends PHPUnit_Framework_TestCase 11 | { 12 | /** 13 | * @var null 14 | */ 15 | protected $attribute; 16 | 17 | /** 18 | * @var string 19 | */ 20 | protected $value; 21 | 22 | /** 23 | * @var array 24 | */ 25 | protected $parameters; 26 | 27 | /** 28 | * @var null 29 | */ 30 | protected $validator; 31 | 32 | /** 33 | * @var object 34 | */ 35 | protected $PersianValidation; 36 | 37 | /** 38 | * create instance of ValidationRules class 39 | * @author Shahrokh Niakan 40 | * @since May 28, 2016 41 | * @return void 42 | */ 43 | public function __construct() 44 | { 45 | $this->PersianValidation = new ValidationRules(); 46 | } 47 | 48 | /** 49 | * unit test of persian alphabet 50 | * @author Shahrokh Niakan 51 | * @since May 28, 2016 52 | * @return void 53 | */ 54 | public function testAlpha() 55 | { 56 | 57 | $this->value = "Shahrokh"; 58 | 59 | $this->assertEquals(false, $this->PersianValidation->Alpha($this->attribute, $this->value, $this->parameters, $this->validator)); 60 | 61 | $this->value = "شاهرخ"; 62 | 63 | $this->assertEquals(true, $this->PersianValidation->Alpha($this->attribute, $this->value, $this->parameters, $this->validator)); 64 | 65 | $this->value = "1111 شاهرخ"; 66 | 67 | $this->assertEquals(false, $this->PersianValidation->Alpha($this->attribute, $this->value, $this->parameters, $this->validator)); 68 | 69 | $this->value = "شاهرخ نیاکان"; 70 | 71 | $this->assertEquals(true, $this->PersianValidation->Alpha($this->attribute, $this->value, $this->parameters, $this->validator)); 72 | 73 | $this->value = "وَحِیُدّ‌الٍمٌاًسی"; 74 | 75 | $this->assertEquals(true, $this->PersianValidation->Alpha($this->attribute, $this->value, $this->parameters, $this->validator)); 76 | 77 | } 78 | 79 | /** 80 | * unit test of persian number 81 | * @author Shahrokh Niakan 82 | * @since May 28, 2016 83 | * @return void 84 | */ 85 | public function testNum() 86 | { 87 | 88 | $this->value = "1234"; 89 | 90 | $this->assertEquals(false, $this->PersianValidation->Num($this->attribute, $this->value, $this->parameters, $this->validator)); 91 | 92 | $this->value = "۱۲۳۴"; 93 | 94 | $this->assertEquals(true, $this->PersianValidation->Num($this->attribute, $this->value, $this->parameters, $this->validator)); 95 | 96 | $this->value = "۱۲۳123"; 97 | 98 | $this->assertEquals(false, $this->PersianValidation->Num($this->attribute, $this->value, $this->parameters, $this->validator)); 99 | 100 | } 101 | 102 | /** 103 | * unit test of persian alphabet and number 104 | * @author Shahrokh Niakan 105 | * @since May 28, 2016 106 | * @return void 107 | */ 108 | public function testAlpha_Num() 109 | { 110 | 111 | $this->value = "Shahrokh1234"; 112 | 113 | $this->assertEquals(false, $this->PersianValidation->AlphaNum($this->attribute, $this->value, $this->parameters, $this->validator)); 114 | 115 | $this->value = "1111شاهرخ"; 116 | 117 | $this->assertEquals(false, $this->PersianValidation->AlphaNum($this->attribute, $this->value, $this->parameters, $this->validator)); 118 | 119 | $this->value = "1111شاهرخ۱۲۳۴"; 120 | 121 | $this->assertEquals(false, $this->PersianValidation->AlphaNum($this->attribute, $this->value, $this->parameters, $this->validator)); 122 | 123 | $this->value = "شاهرخ"; 124 | 125 | $this->assertEquals(true, $this->PersianValidation->AlphaNum($this->attribute, $this->value, $this->parameters, $this->validator)); 126 | 127 | $this->value = "۱۲۳۴"; 128 | 129 | $this->assertEquals(true, $this->PersianValidation->AlphaNum($this->attribute, $this->value, $this->parameters, $this->validator)); 130 | 131 | $this->value = "Shahrokh۱۲۳۴شاهرخ"; 132 | 133 | $this->assertEquals(false, $this->PersianValidation->AlphaNum($this->attribute, $this->value, $this->parameters, $this->validator)); 134 | 135 | $this->value = "۱۲۳۴ شاهرخ"; 136 | 137 | $this->assertEquals(true, $this->PersianValidation->AlphaNum($this->attribute, $this->value, $this->parameters, $this->validator)); 138 | 139 | $this->value = "وَحِیُدّ‌الٍمٌاًسی"; 140 | 141 | $this->assertEquals(true, $this->PersianValidation->AlphaNum($this->attribute, $this->value, $this->parameters, $this->validator)); 142 | 143 | } 144 | 145 | /** 146 | * unit test of iran mobile number 147 | * @author Shahrokh Niakan 148 | * @since May 28, 2016 149 | * @return void 150 | */ 151 | public function testIranMobile() 152 | { 153 | 154 | $this->value = "+989355214655"; 155 | 156 | $this->assertEquals(true, $this->PersianValidation->IranMobile($this->attribute, $this->value, $this->parameters, $this->validator)); 157 | 158 | $this->value = "989355214655"; 159 | 160 | $this->assertEquals(true, $this->PersianValidation->IranMobile($this->attribute, $this->value, $this->parameters, $this->validator)); 161 | 162 | $this->value = "00989355214655"; 163 | 164 | $this->assertEquals(true, $this->PersianValidation->IranMobile($this->attribute, $this->value, $this->parameters, $this->validator)); 165 | 166 | $this->value = "09355214655"; 167 | 168 | $this->assertEquals(true, $this->PersianValidation->IranMobile($this->attribute, $this->value, $this->parameters, $this->validator)); 169 | 170 | $this->value = "09901464762"; 171 | 172 | $this->assertEquals(true, $this->PersianValidation->IranMobile($this->attribute, $this->value, $this->parameters, $this->validator)); 173 | 174 | $this->value = "9901464762"; 175 | 176 | $this->assertEquals(true, $this->PersianValidation->IranMobile($this->attribute, $this->value, $this->parameters, $this->validator)); 177 | 178 | } 179 | 180 | /** 181 | * unit test of sheba number 182 | * @author Shahrokh Niakan 183 | * @since May 28, 2016 184 | * @return void 185 | */ 186 | public function testSheba() 187 | { 188 | 189 | $this->value = "IR062960000000100324200001"; 190 | 191 | $this->assertEquals(true, $this->PersianValidation->Sheba($this->attribute, $this->value, $this->parameters, $this->validator)); 192 | 193 | $this->value = "IR06296000000010032420000"; 194 | 195 | $this->assertEquals(false, $this->PersianValidation->Sheba($this->attribute, $this->value, $this->parameters, $this->validator)); 196 | 197 | $this->value = "00062960000000100324200001"; 198 | 199 | $this->assertEquals(false, $this->PersianValidation->Sheba($this->attribute, $this->value, $this->parameters, $this->validator)); 200 | 201 | } 202 | 203 | /** 204 | * unit test of melli code number 205 | * @author Shahrokh Niakan 206 | * @since May 28, 2016 207 | * @return void 208 | */ 209 | public function testMelliCode() 210 | { 211 | $this->value = "0013542419"; 212 | 213 | $this->assertEquals(true, $this->PersianValidation->MelliCode($this->attribute, $this->value, $this->parameters, $this->validator)); 214 | 215 | $this->value = "3240175800"; 216 | 217 | $this->assertEquals(true, $this->PersianValidation->MelliCode($this->attribute, $this->value, $this->parameters, $this->validator)); 218 | 219 | $this->value = "3240164175"; 220 | 221 | $this->assertEquals(true, $this->PersianValidation->MelliCode($this->attribute, $this->value, $this->parameters, $this->validator)); 222 | 223 | $this->value = "3370075024"; 224 | 225 | $this->assertEquals(true, $this->PersianValidation->MelliCode($this->attribute, $this->value, $this->parameters, $this->validator)); 226 | 227 | $this->value = "0010532129"; 228 | 229 | $this->assertEquals(true, $this->PersianValidation->MelliCode($this->attribute, $this->value, $this->parameters, $this->validator)); 230 | 231 | $this->value = "0860170470"; 232 | 233 | $this->assertEquals(true, $this->PersianValidation->MelliCode($this->attribute, $this->value, $this->parameters, $this->validator)); 234 | 235 | $this->value = "324011122"; 236 | 237 | $this->assertEquals(false, $this->PersianValidation->MelliCode($this->attribute, $this->value, $this->parameters, $this->validator)); 238 | 239 | $this->value = "3213213"; 240 | 241 | $this->assertEquals(false, $this->PersianValidation->MelliCode($this->attribute, $this->value, $this->parameters, $this->validator)); 242 | 243 | $this->value = "0000000000"; 244 | 245 | $this->assertEquals(false, $this->PersianValidation->MelliCode($this->attribute, $this->value, $this->parameters, $this->validator)); 246 | 247 | $this->value = "1111111111"; 248 | 249 | $this->assertEquals(false, $this->PersianValidation->MelliCode($this->attribute, $this->value, $this->parameters, $this->validator)); 250 | 251 | $this->value = "2222222222"; 252 | 253 | $this->assertEquals(false, $this->PersianValidation->MelliCode($this->attribute, $this->value, $this->parameters, $this->validator)); 254 | 255 | $this->value = "3333333333"; 256 | 257 | $this->assertEquals(false, $this->PersianValidation->MelliCode($this->attribute, $this->value, $this->parameters, $this->validator)); 258 | 259 | $this->value = "4444444444"; 260 | 261 | $this->assertEquals(false, $this->PersianValidation->MelliCode($this->attribute, $this->value, $this->parameters, $this->validator)); 262 | 263 | $this->value = "5555555555"; 264 | 265 | $this->assertEquals(false, $this->PersianValidation->MelliCode($this->attribute, $this->value, $this->parameters, $this->validator)); 266 | 267 | $this->value = "6666666666"; 268 | 269 | $this->assertEquals(false, $this->PersianValidation->MelliCode($this->attribute, $this->value, $this->parameters, $this->validator)); 270 | 271 | $this->value = "7777777777"; 272 | 273 | $this->assertEquals(false, $this->PersianValidation->MelliCode($this->attribute, $this->value, $this->parameters, $this->validator)); 274 | 275 | $this->value = "8888888888"; 276 | 277 | $this->assertEquals(false, $this->PersianValidation->MelliCode($this->attribute, $this->value, $this->parameters, $this->validator)); 278 | 279 | $this->value = "9999999999"; 280 | 281 | $this->assertEquals(false, $this->PersianValidation->MelliCode($this->attribute, $this->value, $this->parameters, $this->validator)); 282 | 283 | } 284 | 285 | /** 286 | * unit test of not persian alphabet and number 287 | * @author Shahrokh Niakan 288 | * @since June 13, 2016 289 | * @return void 290 | */ 291 | public function testIsNotPersian() 292 | { 293 | 294 | $this->value = "شاهرخ۱۲۳۴"; 295 | 296 | $this->assertEquals(false, $this->PersianValidation->IsNotPersian($this->attribute, $this->value, $this->parameters, $this->validator)); 297 | 298 | $this->value = "shahrokh"; 299 | 300 | $this->assertEquals(true, $this->PersianValidation->IsNotPersian($this->attribute, $this->value, $this->parameters, $this->validator)); 301 | 302 | $this->value = "Shahrokhشاهرخ۱۲۳۴"; 303 | 304 | $this->assertEquals(false, $this->PersianValidation->IsNotPersian($this->attribute, $this->value, $this->parameters, $this->validator)); 305 | 306 | $this->value = "shahrokhw3289834(!!!%$$(@_)_)_"; 307 | 308 | $this->assertEquals(true, $this->PersianValidation->IsNotPersian($this->attribute, $this->value, $this->parameters, $this->validator)); 309 | 310 | $this->value = 1213131313131; 311 | 312 | $this->assertEquals(false, $this->PersianValidation->IsNotPersian($this->attribute, $this->value, $this->parameters, $this->validator)); 313 | 314 | $this->value = ["Shahrokh"]; 315 | 316 | $this->assertEquals(false, $this->PersianValidation->IsNotPersian($this->attribute, $this->value, $this->parameters, $this->validator)); 317 | 318 | } 319 | 320 | /** 321 | * unit test of check array with custom array count 322 | * @author Shahrokh Niakan 323 | * @since June 13, 2016 324 | * @return void 325 | */ 326 | public function testLimitedArray() 327 | { 328 | $this->value = []; 329 | 330 | $this->assertEquals(true, $this->PersianValidation->LimitedArray($this->attribute, $this->value, $this->parameters, $this->validator)); 331 | 332 | $this->value = []; 333 | $this->parameters[0] = 1; 334 | 335 | $this->assertEquals(true, $this->PersianValidation->LimitedArray($this->attribute, $this->value, $this->parameters, $this->validator)); 336 | 337 | $this->value = ["a"]; 338 | $this->parameters[0] = 2; 339 | 340 | $this->assertEquals(true, $this->PersianValidation->LimitedArray($this->attribute, $this->value, $this->parameters, $this->validator)); 341 | 342 | $this->value = ["a", "b"]; 343 | $this->parameters[0] = 2; 344 | 345 | $this->assertEquals(true, $this->PersianValidation->LimitedArray($this->attribute, $this->value, $this->parameters, $this->validator)); 346 | 347 | $this->value = ["a", "b", "c"]; 348 | $this->parameters[0] = 2; 349 | 350 | $this->assertEquals(false, $this->PersianValidation->LimitedArray($this->attribute, $this->value, $this->parameters, $this->validator)); 351 | 352 | } 353 | 354 | /** 355 | * unit test of unsigned number 356 | * @author Shahrokh Niakan 357 | * @since July 22, 2016 358 | * @return void 359 | */ 360 | public function testUnSignedNum() 361 | { 362 | 363 | $this->value = 11; 364 | 365 | $this->assertEquals(true, $this->PersianValidation->UnSignedNum($this->attribute, $this->value, $this->parameters, $this->validator)); 366 | 367 | $this->value = -11; 368 | 369 | $this->assertEquals(false, $this->PersianValidation->UnSignedNum($this->attribute, $this->value, $this->parameters, $this->validator)); 370 | 371 | $this->value = 11.22; 372 | 373 | $this->assertEquals(false, $this->PersianValidation->UnSignedNum($this->attribute, $this->value, $this->parameters, $this->validator)); 374 | 375 | } 376 | 377 | /** 378 | * unit test of alpha space 379 | * @author Shahrokh Niakan 380 | * @since Agu 3, 2016 381 | * @return void 382 | */ 383 | public function testAlphaSpace() 384 | { 385 | 386 | $this->value = "shahrokh niakan"; 387 | 388 | $this->assertEquals(true, $this->PersianValidation->AlphaSpace($this->attribute, $this->value, $this->parameters, $this->validator, $this->parameters, $this->validator)); 389 | 390 | $this->value = "shahrokh 121"; 391 | 392 | $this->assertEquals(false, $this->PersianValidation->AlphaSpace($this->attribute, $this->value, $this->parameters, $this->validator, $this->parameters, $this->validator)); 393 | 394 | $this->value = "وَحِیُدّ‌الٍمٌاًسی"; 395 | 396 | $this->assertEquals(true, $this->PersianValidation->AlphaSpace($this->attribute, $this->value, $this->parameters, $this->validator, $this->parameters, $this->validator)); 397 | 398 | } 399 | 400 | /** 401 | * unit test of url 402 | * @author Shahrokh Niakan 403 | * @since Agu 17, 2016 404 | * @return void 405 | */ 406 | public function testUrl() 407 | { 408 | 409 | $this->value = "http://hello.com"; 410 | 411 | $this->assertEquals(true, $this->PersianValidation->Url($this->attribute, $this->value, $this->parameters, $this->validator)); 412 | 413 | $this->value = "http/df;fdl"; 414 | 415 | $this->assertEquals(false, $this->PersianValidation->Url($this->attribute, $this->value, $this->parameters, $this->validator)); 416 | 417 | } 418 | 419 | /** 420 | * unit test of domain 421 | * @author Shahrokh Niakan 422 | * @since Agu 17, 2016 423 | * @return void 424 | */ 425 | public function testDomain() 426 | { 427 | 428 | $this->value = "www.adele.com"; 429 | 430 | $this->assertEquals(true, $this->PersianValidation->Domain($this->attribute, $this->value, $this->parameters, $this->validator)); 431 | 432 | $this->value = "xn--pgba0a.com"; 433 | 434 | $this->assertEquals(true, $this->PersianValidation->Domain($this->attribute, $this->value, $this->parameters, $this->validator)); 435 | 436 | $this->value = "iran-go.ir"; 437 | 438 | $this->assertEquals(true, $this->PersianValidation->Domain($this->attribute, $this->value, $this->parameters, $this->validator)); 439 | 440 | $this->value = "dshgf---df.w"; 441 | 442 | $this->assertEquals(false, $this->PersianValidation->Domain($this->attribute, $this->value, $this->parameters, $this->validator)); 443 | 444 | $this->value = "www.ad#le.com"; 445 | 446 | $this->assertEquals(false, $this->PersianValidation->Domain($this->attribute, $this->value, $this->parameters, $this->validator)); 447 | 448 | $this->value = "www.adele.co,m"; 449 | 450 | $this->assertEquals(false, $this->PersianValidation->Domain($this->attribute, $this->value, $this->parameters, $this->validator)); 451 | 452 | } 453 | 454 | /** 455 | * unit test of more 456 | * @author Shahrokh Niakan 457 | * @since Agu 24, 2016 458 | * @return void 459 | */ 460 | public function testMore() 461 | { 462 | 463 | $this->value = 10; 464 | 465 | $this->parameters[0] = 9; 466 | 467 | $this->assertEquals(true, $this->PersianValidation->More($this->attribute, $this->value, $this->parameters, $this->validator)); 468 | 469 | $this->parameters[0] = 11; 470 | 471 | $this->assertEquals(false, $this->PersianValidation->More($this->attribute, $this->value, $this->parameters, $this->validator)); 472 | 473 | $this->parameters[0] = 10; 474 | 475 | $this->assertEquals(false, $this->PersianValidation->More($this->attribute, $this->value, $this->parameters, $this->validator)); 476 | 477 | } 478 | 479 | /** 480 | * unit test of less 481 | * @author Shahrokh Niakan 482 | * @since Agu 24, 2016 483 | * @return void 484 | */ 485 | public function testLess() 486 | { 487 | 488 | $this->value = 10; 489 | 490 | $this->parameters[0] = 11; 491 | 492 | $this->assertEquals(true, $this->PersianValidation->Less($this->attribute, $this->value, $this->parameters, $this->validator)); 493 | 494 | $this->parameters[0] = 9; 495 | 496 | $this->assertEquals(false, $this->PersianValidation->Less($this->attribute, $this->value, $this->parameters, $this->validator)); 497 | 498 | $this->parameters[0] = 10; 499 | 500 | $this->assertEquals(false, $this->PersianValidation->Less($this->attribute, $this->value, $this->parameters, $this->validator)); 501 | 502 | } 503 | 504 | /** 505 | * unit test of iran phone number 506 | * @author Shahrokh Niakan 507 | * @since Agu 24, 2016 508 | * @return void 509 | */ 510 | public function testIranPhone() 511 | { 512 | 513 | $this->value = '07236445'; 514 | 515 | $this->assertEquals(false, $this->PersianValidation->IranPhone($this->attribute, $this->value, $this->parameters, $this->validator)); 516 | 517 | $this->value = '7236445'; 518 | 519 | $this->assertEquals(false, $this->PersianValidation->IranPhone($this->attribute, $this->value, $this->parameters, $this->validator)); 520 | 521 | $this->value = '17236445'; 522 | 523 | $this->assertEquals(false, $this->PersianValidation->IranPhone($this->attribute, $this->value, $this->parameters, $this->validator)); 524 | 525 | $this->value = '37236445'; 526 | 527 | $this->assertEquals(true, $this->PersianValidation->IranPhone($this->attribute, $this->value, $this->parameters, $this->validator)); 528 | 529 | } 530 | 531 | /** 532 | * unit test of iran phone number with the area code 533 | * @author Amir Hosseini 534 | * @since Jan 28, 2019 535 | * @return void 536 | */ 537 | public function testIranPhoneWithAreaCode() 538 | { 539 | 540 | $this->value = '07236445'; 541 | 542 | $this->assertEquals(false, $this->PersianValidation->IranPhoneWithAreaCode($this->attribute, $this->value, $this->parameters, $this->validator)); 543 | 544 | $this->value = '7236445'; 545 | 546 | $this->assertEquals(false, $this->PersianValidation->IranPhoneWithAreaCode($this->attribute, $this->value, $this->parameters, $this->validator)); 547 | 548 | $this->value = '17236445'; 549 | 550 | $this->assertEquals(false, $this->PersianValidation->IranPhoneWithAreaCode($this->attribute, $this->value, $this->parameters, $this->validator)); 551 | 552 | $this->value = '37236445'; 553 | 554 | $this->assertEquals(false, $this->PersianValidation->IranPhoneWithAreaCode($this->attribute, $this->value, $this->parameters, $this->validator)); 555 | 556 | $this->value = '02137236445'; 557 | 558 | $this->assertEquals(true, $this->PersianValidation->IranPhoneWithAreaCode($this->attribute, $this->value, $this->parameters, $this->validator)); 559 | 560 | } 561 | 562 | /** 563 | * unit test of payment card number 564 | * @author Mojtaba Anisi 565 | * @since Oct 2, 2016 566 | * @return void 567 | */ 568 | public function testCardNumber() 569 | { 570 | $this->value = '6274-1290-0547-3742'; 571 | 572 | $this->assertEquals(false, $this->PersianValidation->CardNumber($this->attribute, $this->value, $this->parameters, $this->validator)); 573 | 574 | $this->value = '6274129107473842'; 575 | 576 | $this->assertEquals(false, $this->PersianValidation->CardNumber($this->attribute, $this->value, $this->parameters, $this->validator)); 577 | 578 | $this->value = '6274 1290 0547 3742'; 579 | 580 | $this->assertEquals(false, $this->PersianValidation->CardNumber($this->attribute, $this->value, $this->parameters, $this->validator)); 581 | 582 | $this->value = '627412900742'; 583 | 584 | $this->assertEquals(false, $this->PersianValidation->CardNumber($this->attribute, $this->value, $this->parameters, $this->validator)); 585 | 586 | $this->value = '62741290054737423252'; 587 | 588 | $this->assertEquals(false, $this->PersianValidation->CardNumber($this->attribute, $this->value, $this->parameters, $this->validator)); 589 | 590 | $this->value = '6274129005473742'; 591 | 592 | $this->assertEquals(true, $this->PersianValidation->CardNumber($this->attribute, $this->value, $this->parameters, $this->validator)); 593 | } 594 | 595 | /** 596 | * unit test of alpha and special characters 597 | * @author Shahrokh Niakan 598 | * @since Oct 7, 2016 599 | * @return void 600 | */ 601 | public function testAdress() 602 | { 603 | 604 | $this->value = "Iran, Tehran - pardis"; 605 | 606 | $this->assertEquals(true, $this->PersianValidation->Address($this->attribute, $this->value, $this->parameters, $this->validator)); 607 | 608 | $this->value = "ایران، تهران - پردیس"; 609 | 610 | $this->assertEquals(true, $this->PersianValidation->Address($this->attribute, $this->value, $this->parameters, $this->validator)); 611 | 612 | $this->value = "Iran / Tehran / pardis / 16"; 613 | 614 | $this->assertEquals(true, $this->PersianValidation->Address($this->attribute, $this->value, $this->parameters, $this->validator)); 615 | 616 | $this->value = "ایران \ تهران \ پردیس \ ۱۶"; 617 | 618 | $this->assertEquals(true, $this->PersianValidation->Address($this->attribute, $this->value, $this->parameters, $this->validator)); 619 | 620 | $this->value = "Iran, Tehran & pardis"; 621 | 622 | $this->assertEquals(false, $this->PersianValidation->Address($this->attribute, $this->value, $this->parameters, $this->validator)); 623 | 624 | } 625 | 626 | /** 627 | * unit test of iran postal code 628 | * @author Shahrokh Niakan 629 | * @since Apr 5, 2017 630 | * @return void 631 | */ 632 | public function testIranPostalCode() 633 | { 634 | 635 | $this->value = "1619735744"; 636 | 637 | $this->assertEquals(true, $this->PersianValidation->IranPostalCode($this->attribute, $this->value, $this->parameters, $this->validator)); 638 | 639 | $this->value = "16197-35744"; 640 | 641 | $this->assertEquals(true, $this->PersianValidation->IranPostalCode($this->attribute, $this->value, $this->parameters, $this->validator)); 642 | 643 | $this->value = "116197-35744"; 644 | 645 | $this->assertEquals(false, $this->PersianValidation->IranPostalCode($this->attribute, $this->value, $this->parameters, $this->validator)); 646 | 647 | $this->value = "11619735744"; 648 | 649 | $this->assertEquals(false, $this->PersianValidation->IranPostalCode($this->attribute, $this->value, $this->parameters, $this->validator)); 650 | 651 | } 652 | 653 | 654 | /** 655 | * unit test of apk packge name 656 | * @author Shahrokh Niakan 657 | * @since May 31, 2017 658 | * @return void 659 | */ 660 | public function testPackageName() 661 | { 662 | 663 | $this->value = "com.adele"; 664 | 665 | $this->assertEquals(true, $this->PersianValidation->PackageName($this->attribute, $this->value, $this->parameters, $this->validator)); 666 | 667 | $this->value = "com.adele.adele"; 668 | 669 | $this->assertEquals(true, $this->PersianValidation->PackageName($this->attribute, $this->value, $this->parameters, $this->validator)); 670 | 671 | $this->value = "com."; 672 | 673 | $this->assertEquals(false, $this->PersianValidation->PackageName($this->attribute, $this->value, $this->parameters, $this->validator)); 674 | 675 | $this->value = "com.adele."; 676 | 677 | $this->assertEquals(false, $this->PersianValidation->PackageName($this->attribute, $this->value, $this->parameters, $this->validator)); 678 | 679 | } 680 | 681 | } 682 | --------------------------------------------------------------------------------