You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
}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";
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 = [];
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 )
The text was updated successfully, but these errors were encountered: