Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cedula panama en PHP #10

Open
merlos opened this issue Mar 16, 2023 · 1 comment
Open

Cedula panama en PHP #10

merlos opened this issue Mar 16, 2023 · 1 comment

Comments

@merlos
Copy link
Owner

merlos commented Mar 16, 2023

Zubin me facilitó este codigo. Pendiente de agregar al repo:

Función PHP "validate_id":


function validate_id($id){
$a = "";
$b = "";
$c = "";
$group = [];
$isValid = "False";
$isComplete = "False";
$unified = "";
$result = [];

$pattern = '/^P$|^(?:PE|E|N|[23456789]|23456789?|1[0123]?|1[0123]?(?:A|P)?)$|^(?:PE|E|N|[23456789]|23456789?|1[0123]?|1[0123]?(?:AV|PI)?)-?$|^(?:PE|E|N|23456789?|1[0123]?(?:AV|PI)?)-(?:\d{1,4})-?$|^(PE|E|N|23456789?|1[0123]?(?:AV|PI)?)-(\d{1,4})-(\d{1,6})$/i';

if(preg_match($pattern, $id, $coincidence, PREG_OFFSET_CAPTURE)){

$isValid = "True";
$isComplete = "True";

array_push($group, $coincidence[1][0], $coincidence[2][0], $coincidence[3][0]); //Agregando valores al arreglo $grupos

// PI and AV
if(preg_match('/^(1[0123]?|[23456789])(AV|PI)$/', $group[0], $coincidence, PREG_OFFSET_CAPTURE)){

if($coincidence[2][0] == 'PI' || $coincidence[2][0] == 'AV'){

$a = "0".$group[0];

}
}

// PE
if($group[0] == "PE" ){

$a = str_repeat("\x20", 2).$group[0];

// E
}elseif($group[0] == "E"){

$a = str_repeat("\x20", 2).$group[0].str_repeat("\x20", 1);

// N
}elseif($group[0] == "N"){

$a = str_repeat("\x20", 2).$group[0].str_repeat("\x20", 1);

// 1 - 9
}elseif ($group[0] >= 1 && $group[0] <= 9){

$a = "0".$group[0].str_repeat("\x20", 2);

// two digits
}elseif($group[0] > 9){

$a = $group[0].str_repeat("\x20", 2);

}

// Giving unified format
if(strlen($group[1]) <= "4"){

if(strlen($group[1]) === "1"){

$b = "0"."0"."0".$group[1];

}elseif(strlen($group[1]) == "2"){

$b = "0"."0".$group[1];

}elseif(strlen($group[1]) == "3"){

$b = "0".$group[1];

}elseif(strlen($group[1]) == "4"){

$b = $group[1];

}

}

// Giving unified format
if((strlen($group[2])) <= "5"){

if((strlen($group[2])) == "1"){

$c = "0"."0"."0"."0".$group[2];

}elseif(strlen($group[2]) == "2"){

$c = "0"."0"."0".$group[2];

}elseif(strlen($group[2]) == "3"){

$c = "0"."0".$group[2];

}elseif(strlen($group[2]) == "4"){

$c = "0".$group[2];

}elseif(strlen($group[2]) == "5"){

$c = $group[2];

}

}
//assigning unified value
$unified = $a.$b.$c;

//assigning values to array
$result['isValid'] = $isValid;
$result['isComplete'] = $isComplete;
$result['id'] = $group[0]."-".$group[1]."-".$group[2];
$result['unified'] = $unified;

}else{
//assigning values to the array, only if an "id" is entered with error
$result['isValid'] = $isValid;
$result['isComplete'] = $isComplete;
$result['id'] = "None";
$result['unified'] = "None";

}
//array is returned
return $result;

}

Ejemplo:

$id = "5-123-1234";
$ced = validate_id($id);
print_r($ced);

Resultado:

Array ( [isValid] => True [isComplete] => True [id] => 5-123-1234 [unified] => 05 012301234 )

@Vlm27
Copy link

Vlm27 commented Mar 21, 2024

Hi, is possible to search someone in Panama w a cédula or id?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants