-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCodeMelli.php
More file actions
115 lines (96 loc) · 1.92 KB
/
CodeMelli.php
File metadata and controls
115 lines (96 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
/**
* In the name of God
*
* Validate National Iranian Code
*
* @package melliCode
* @version 1.0.0 mellicode.php Monday, June 15, 2015
* @author Saeed Sajadi
* @web http://saeedsajadi.ir
* @email smart_twists@yahoo.co.uk
*/
namespase CodeMelli
class CodeMelli
{
/**
* Hold National Code
*
* @access Protected
* @var Integer
*/
protected static $nationalCode;
/**
* Incorrect List
*
* @access Protected
* @var Integer
*/
protected static $notNationalCode = array(
"1111111111",
"2222222222",
"3333333333",
"4444444444",
"5555555555",
"6666666666",
"7777777777",
"8888888888",
"9999999999",
"0000000000");
/**
* Construct
*
* @access Public
* @var Empty
*/
public function __construct()
{
}
/**
* National Validation Code
*
* @access Public
* @var Integer
*/
public function nationalCode($code)
{
self::$nationalCode = trim($code);
if(self::validCode())
{
$melliCode = self::$nationalCode;
$subMid = self::subMidNumbers($melliCode, 10, 1);
$getNum = 0;
for($i = 1; $i < 10; $i++)
$getNum += (self::subMidNumbers($melliCode, $i, 1) * (11 - $i));
$modulus = ($getNum % 11);
if((($modulus < 2) && ($subMid == $modulus)) || (($modulus >= 2) && ($subMid == (11 - $modulus))))
return true;
}
return false;
}
/**
* Validate
*
* @access Protected
* @var Boolean
*/
protected function validCode()
{
$melliCode = self::$nationalCode;
if((is_numeric($melliCode)) && (strlen($melliCode) == 10) && (strspn($melliCode, $melliCode[0]) != strlen($melliCode)))
return true;
return false;
}
/**
* Get Portion of String Specified
*
* @access Protected
* @var Integer
*/
protected function subMidNumbers($number, $start, $length)
{
$number = substr($number, ($start - 1), $length);
return $number;
}
}
?>