Created
September 18, 2014 14:18
-
-
Save erickertz/fdfb74c3e0fb77be7687 to your computer and use it in GitHub Desktop.
ddawg boog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function setCustomValidationrules() | |
{ | |
$this->validator->addExtension('elevate_number', function($attribute, $value, $parameters) | |
{ | |
$elevate_num = $value; | |
if (empty($elevate_num)) { | |
return false; | |
} | |
if(strlen($elevate_num) != 11){ | |
return false; | |
} | |
$elevate_digits = str_split($elevate_num); | |
$digit_total = 0; | |
$digit_total += $elevate_digits[0] * 6; | |
$digit_total += $elevate_digits[1] * 5; | |
$digit_total += $elevate_digits[2] * 4; | |
$digit_total += $elevate_digits[3] * 3; | |
$digit_total += $elevate_digits[4] * 8; | |
$digit_total += $elevate_digits[5] * 7; | |
$digit_total += $elevate_digits[6] * 6; | |
$digit_total += $elevate_digits[7] * 5; | |
$digit_total += $elevate_digits[8] * 4; | |
$digit_total += $elevate_digits[9] * 3; | |
$last_digit = $elevate_digits[10]; | |
$remainder = $digit_total % 11; | |
if ($remainder < 2) { | |
$check_digit = 0; | |
} else { | |
$check_digit = 11 - $remainder; | |
} | |
if ($check_digit == $last_digit) { | |
return true; | |
} | |
return false; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment