Guest User

Untitled

a guest
Nov 21st, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. <?php
  2.  
  3. class melliCode
  4. {
  5. /**
  6. * Hold National Code
  7. *
  8. * @access Protected
  9. * @var Integer
  10. */
  11. protected static $nationalCode = int;
  12.  
  13. /**
  14. * Incorrect List
  15. *
  16. * @access Protected
  17. * @var Integer
  18. */
  19. protected static $notNationalCode = array(
  20. "1111111111",
  21. "2222222222",
  22. "3333333333",
  23. "4444444444",
  24. "5555555555",
  25. "6666666666",
  26. "7777777777",
  27. "8888888888",
  28. "9999999999",
  29. "0000000000");
  30.  
  31. /**
  32. * Construct
  33. *
  34. * @access Public
  35. * @var Empty
  36. */
  37. public function __construct()
  38. {
  39.  
  40. }
  41.  
  42. /**
  43. * National Validation Code
  44. *
  45. * @access Public
  46. * @var Integer
  47. */
  48. public function nationalCode($code)
  49. {
  50. self::$nationalCode = trim($code);
  51.  
  52. if(self::validCode())
  53. {
  54. $melliCode = self::$nationalCode;
  55.  
  56. $subMid = self::subMidNumbers($melliCode, 10, 1);
  57.  
  58. $getNum = 0;
  59.  
  60. for($i = 1; $i < 10; $i++)
  61. $getNum += (self::subMidNumbers($melliCode, $i, 1) * (11 - $i));
  62.  
  63. $modulus = ($getNum % 11);
  64.  
  65. if((($modulus < 2) && ($subMid == $modulus)) || (($modulus >= 2) && ($subMid == (11 - $modulus))))
  66. return true;
  67. }
  68.  
  69. return false;
  70. }
  71.  
  72. /**
  73. * Validate
  74. *
  75. * @access Protected
  76. * @var Boolean
  77. */
  78. protected function validCode()
  79. {
  80. $melliCode = self::$nationalCode;
  81.  
  82. if((is_numeric($melliCode)) && (strlen($melliCode) == 10) && (strspn($melliCode, $melliCode[0]) != strlen($melliCode)))
  83. return true;
  84.  
  85. return false;
  86. }
  87.  
  88. /**
  89. * Get Portion of String Specified
  90. *
  91. * @access Protected
  92. * @var Integer
  93. */
  94. protected function subMidNumbers($number, $start, $length)
  95. {
  96. $number = substr($number, ($start - 1), $length);
  97.  
  98. return $number;
  99. }
  100. }
  101.  
  102. ?>
Add Comment
Please, Sign In to add comment