Skip to content

Commit

Permalink
Merge pull request #15
Browse files Browse the repository at this point in the history
refactor[validateIranianNationalCode]: replace concatenating with str_pad
  • Loading branch information
sadegh19b authored Jul 19, 2023
2 parents 9121469 + 646a516 commit db2ff14
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions src/PersianValidators.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,11 +368,7 @@ public function validateIranianNationalCode($attribute, $value, $parameters)

$sub = 0;

if (strlen($value) == 8) {
$value = '00' . $value;
} elseif (strlen($value) == 9) {
$value = '0' . $value;
}
$value = str_pad($value, 10, '0', STR_PAD_LEFT);

for ($i = 0; $i <= 8; $i++) {
$sub = $sub + ( $value[$i] * ( 10 - $i ) );
Expand All @@ -384,11 +380,7 @@ public function validateIranianNationalCode($attribute, $value, $parameters)
$control = 11 - ( $sub % 11 );
}

if ($value[9] == $control) {
return true;
} else {
return false;
}
return (int) $value[9] === $control;
}

/**
Expand Down

0 comments on commit db2ff14

Please sign in to comment.