for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Milwad\LaravelValidate\Rules;
use Illuminate\Contracts\Validation\Rule;
class ValidNationalCard implements Rule
{
/**
* Check national card is valid.
*/
public function passes($attribute, $value): bool
if (! preg_match('/^\d{10}$/', $value)) {
return false;
}
if (preg_match('/^(.)\1*$/u', $value)) {
for ($i = 0, $sum = 0; $i < 9; $i++) {
$sum += ((10 - $i) * intval(substr($value, $i, 1)));
$ret = $sum % 11;
$parity = intval(substr($value, 9, 1));
if (($ret < 2 && $ret == $parity) || ($ret >= 2 && $ret == 11 - $parity)) {
return true;
* Get the validation error message.
public function message(): string
return __('validate.national-card');