diff --git a/api/lab/save_paciente.php b/api/lab/save_paciente.php
index 7b3cd4a..731c83a 100644
--- a/api/lab/save_paciente.php
+++ b/api/lab/save_paciente.php
@@ -26,8 +26,15 @@ try {
$telVal = trim($datos['telefono'] ?? '');
if ($telVal !== '') {
$telDigits = preg_replace('/[^0-9]/', '', $telVal);
- if (!preg_match('/^(57)?3\d{9}$/', $telDigits)) {
- jsonError('El celular debe comenzar por 3 y tener 10 dígitos. Ej: 3001234567.');
+ // Número colombiano: 10 dígitos empezando en 3, o con prefijo 57
+ $esColombia = preg_match('/^57/', $telDigits) || (strlen($telDigits) === 10 && $telDigits[0] === '3');
+ if ($esColombia) {
+ $sinPrefijo = preg_replace('/^57/', '', $telDigits);
+ if (!preg_match('/^3\d{9}$/', $sinPrefijo)) {
+ jsonError('El celular colombiano debe comenzar por 3 y tener 10 dígitos. Ej: 3001234567.');
+ }
+ } elseif (strlen($telDigits) < 6 || strlen($telDigits) > 15) {
+ jsonError('El número telefónico no es válido (debe tener entre 6 y 15 dígitos).');
}
}
$docVal = trim($datos['numero_documento'] ?? '');
diff --git a/enfermero_portal.php b/enfermero_portal.php
index 2dada98..00d1c49 100644
--- a/enfermero_portal.php
+++ b/enfermero_portal.php
@@ -1717,11 +1717,21 @@ const agendaNueva = {
// Validar teléfono si fue ingresado
const telRaw = document.getElementById('na-np-telefono').value.trim();
if (telRaw) {
+ const prefijo = document.getElementById('na-np-prefijo').value || '57';
const telDigits = telRaw.replace(/[^0-9]/g, '');
- if (!/^(57)?3\d{9}$/.test(telDigits)) {
+ const esColombia = prefijo === '57';
+ if (esColombia) {
+ const sinPref = telDigits.replace(/^57/, '');
+ if (!/^3\d{9}$/.test(sinPref)) {
+ btn.disabled = false;
+ btn.innerHTML = 'Agendar';
+ this._mostrarError('El celular colombiano debe comenzar por 3 y tener 10 dígitos. Ej: 3001234567.');
+ return;
+ }
+ } else if (telDigits.length < 6 || telDigits.length > 15) {
btn.disabled = false;
btn.innerHTML = 'Agendar';
- this._mostrarError('El celular debe comenzar por 3 y tener 10 dígitos. Ej: 3001234567.');
+ this._mostrarError('El número telefónico no es válido (entre 6 y 15 dígitos).');
return;
}
}
diff --git a/lab_pacientes.php b/lab_pacientes.php
index aac70eb..f1e9916 100644
--- a/lab_pacientes.php
+++ b/lab_pacientes.php
@@ -373,9 +373,18 @@ async function guardarPaciente() {
if (tel.startsWith('+')) tel = tel.slice(1);
if (tel.length === 10) tel = prefijo + tel;
datos.telefono = tel || null;
- // Validar formato de celular
- if (datos.telefono && !/^(57)?3\d{9}$/.test(datos.telefono)) {
- mostrarToast('El celular debe comenzar por 3 y tener 10 dígitos. Ej: 3001234567.', 'danger'); return;
+ // Validar formato: colombiano (57) exige iniciar en 3 con 10 dígitos; otros países solo longitud
+ if (datos.telefono) {
+ const digits = datos.telefono.replace(/[^0-9]/g, '');
+ const esColombia = prefijo === '57';
+ if (esColombia) {
+ const sinPref = digits.replace(/^57/, '');
+ if (!/^3\d{9}$/.test(sinPref)) {
+ mostrarToast('El celular colombiano debe comenzar por 3 y tener 10 dígitos. Ej: 3001234567.', 'danger'); return;
+ }
+ } else if (digits.length < 6 || digits.length > 15) {
+ mostrarToast('El número telefónico no es válido (entre 6 y 15 dígitos).', 'danger'); return;
+ }
}
const r = await fetch('api/lab/save_paciente.php', {