This commit is contained in:
Lizandro Guarnizo
2026-05-27 21:39:53 -05:00
parent 2f72d87c3b
commit b317639258
3 changed files with 33 additions and 7 deletions
+12 -3
View File
@@ -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', {