<?php
/*
Validar teléfonos argentinos con una expresión regular
https://es.stackoverflow.com/q/136325/127
*/
// Valida teléfonos argentinos (fijos, móviles, no geográficos o sociales)
// Si es válido, devuelve un array con el número parseado.
//
function tel_argentino( $tel ) {
$re = '/^(?:((?P<p1>(?:\( ?)?+)(?:\+|00)?(54)(?<p2>(?: ?\))?+)(?P<sep>(?:[-.]| (?:[-.] )?)?+)(?:(?&p1)(9)(?&p2)(?&sep))?|(?&p1)(0)(?&p2)(?&sep))?+(?&p1)(11|([23]\d{2}(\d)??|(?(-10)(?(-5)(?!)|[68]\d{2})|(?!))))(?&p2)(?&sep)(?(-5)|(?&p1)(15)(?&p2)(?&sep))?(?:([3-6])(?&sep)|([12789]))(\d(?(-5)|\d(?(-6)|\d)))(?&sep)(\d{4})|(1\d{2}|911))$/D';
,$internacional_completo,,$internacional,,,$internacional_celu,$prefijo_acceso,$area,,,
$prefijo_celu,$local_1a,$local_1b,$local_1c,$local_2,$numero_social
$local_1 = $local_1a . $local_1b . $local_1c;
$local = $local_1 . $local_2;
$es_fijo = !($internacional_celu || $prefijo_celu);
$numero = $area.$local.$numero_social;
$completo = $internacional.$internacional_celu.$area.$prefijo_celu.$local.$numero_social;
'numero','completo','internacional','internacional_celu','area',
'prefijo_celu','local','local_1','local_2','numero_social','es_fijo'
);
}
return false;
}
// ----- PRUEBAS -----
//
$pruebas = [
'+54 11 4444-0000', '+54 341 1118888', '(+549261)1234567', '(0351)333-4444',
'266 - 999 - 0000', '343-1238888', '+5491188884444', '543412228888',
'(54)233-15-111-2222', '(+54-343)9990000', '+54 (3436) 99-0000',
'(0)8003337333', '+54 11(4444)0000', '+54 341 1111-888', '(+54261)12-34567',
'(03510)3334444', '266-99-0000', '4444-5555', '34-5555-0000'
];
$fcolumnas = "%19s %-3s %-11s %4s %4s %-4s %s\n";
printf($fcolumnas,'PRUEBA',"\u{2754}",'NUMERO','AREA','L1 ','L2','FIJO?');
foreach ($pruebas as &$prueba) {
$tel = tel_argentino($prueba);
$fcolumnas,
$prueba,($tel?"\u{2714}":"\u{2716}"),
$tel['numero'],$tel['area'],$tel['local_1'],$tel['local_2'],($tel?($tel['es_fijo']?'sí':'no'):'')
);
}
PD9waHAKLyoKCVZhbGlkYXIgdGVsw6lmb25vcyBhcmdlbnRpbm9zIGNvbiB1bmEgZXhwcmVzacOzbiByZWd1bGFyCglodHRwczovL2VzLnN0YWNrb3ZlcmZsb3cuY29tL3EvMTM2MzI1LzEyNwoqLwoKLy8gVmFsaWRhIHRlbMOpZm9ub3MgYXJnZW50aW5vcyAoZmlqb3MsIG3Ds3ZpbGVzLCBubyBnZW9ncsOhZmljb3MgbyBzb2NpYWxlcykKLy8gU2kgZXMgdsOhbGlkbywgZGV2dWVsdmUgdW4gYXJyYXkgY29uIGVsIG7Dum1lcm8gcGFyc2VhZG8uCi8vCmZ1bmN0aW9uIHRlbF9hcmdlbnRpbm8oICR0ZWwgKSB7CiAgICAkcmUgPSAnL14oPzooKD9QPHAxPig/OlwoID8pPyspKD86XCt8MDApPyg1NCkoPzxwMj4oPzogP1wpKT8rKSg/UDxzZXA+KD86Wy0uXXwgKD86Wy0uXSApPyk/KykoPzooPyZwMSkoOSkoPyZwMikoPyZzZXApKT98KD8mcDEpKDApKD8mcDIpKD8mc2VwKSk/Kyg/JnAxKSgxMXwoWzIzXVxkezJ9KFxkKT8/fCg/KC0xMCkoPygtNSkoPyEpfFs2OF1cZHsyfSl8KD8hKSkpKSg/JnAyKSg/JnNlcCkoPygtNSl8KD8mcDEpKDE1KSg/JnAyKSg/JnNlcCkpPyg/OihbMy02XSkoPyZzZXApfChbMTI3ODldKSkoXGQoPygtNSl8XGQoPygtNil8XGQpKSkoPyZzZXApKFxkezR9KXwoMVxkezJ9fDkxMSkpJC9EJzsKICAgIGlmIChwcmVnX21hdGNoKCRyZSwkdGVsLCRtYXRjaCkpIHsKICAgICAgICBsaXN0KAogICAgICAgICAgICAsJGludGVybmFjaW9uYWxfY29tcGxldG8sLCRpbnRlcm5hY2l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