• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: VALIDATION DNI AND NIE

VALIDATION DNI AND NIE 6 months 1 week ago #43047

Good afternoon, I leave you the function that validates both the ID and the NIE

class RSFormProCustomValidations extends RSFormProValidations
{
public static function validarDNI_NIE($value, $extra = null, $data = null) {
$dni_nie = strtoupper($value);
$val= false;

if (preg_match('/^[0-9]{8}[A-Z]$/', $dni_nie)) {
// Es un DNI
$numero = substr($dni_nie, 0, 8);
$letra = substr($dni_nie, 8, 1);
$map = 'TRWAGMYFPDXBNJZSQVHLCKE';
$index = $numero % 23;

if ($letra === $map[$index]) {
$val = true;
}

} elseif (preg_match('/^[XYZ][0-9]{7}[A-Z]$/', $dni_nie)) {
// Es un NIE
$numero = substr($dni_nie, 1, 7);
$letra = substr($dni_nie, 8, 1);
$map = 'TRWAGMYFPDXBNJZSQVHLCKE';

$letraInicial = $dni_nie[0];
$ajuste = ($letraInicial === 'X') ? 0 : (($letraInicial === 'Y') ? 10000000 : 20000000);
$numero += $ajuste;

$index = $numero % 23;

if ($letra === $map[$index] || ($letraInicial === 'X' && $letra === 'T')) {
$val = true;
}


}

return $val; // Retorna el valor de $val
}


}
The administrator has disabled public write access.
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!