cambios
This commit is contained in:
@@ -345,12 +345,38 @@ async function guardarPaciente() {
|
||||
const datos = Object.fromEntries(new FormData(form).entries());
|
||||
if (!datos.id) delete datos.id;
|
||||
|
||||
// ── Validaciones de formato ───────────────────────────────────────────
|
||||
const nombre = (datos.nombre_completo || '').trim();
|
||||
if (!/^[\p{L}\s'\-\.]+$/u.test(nombre)) {
|
||||
mostrarToast('El nombre solo debe contener letras, tildes y espacios.', 'danger'); return;
|
||||
}
|
||||
if (nombre.split(/\s+/).filter(Boolean).length < 2) {
|
||||
mostrarToast('Ingresa nombre y apellido completos (mínimo 2 palabras).', 'danger'); return;
|
||||
}
|
||||
const docVal = (datos.numero_documento || '').trim();
|
||||
const tipoDoc = (document.getElementById('pac-tipo-doc')?.value || datos.tipo_documento || 'CC');
|
||||
if (docVal && ['CC','TI','RC','CE'].includes(tipoDoc)) {
|
||||
const docDigits = docVal.replace(/[^0-9]/g, '');
|
||||
if (docDigits.length < 4 || docDigits.length > 12) {
|
||||
mostrarToast('La cédula/TI debe tener entre 4 y 12 dígitos.', 'danger'); return;
|
||||
}
|
||||
}
|
||||
const emailVal = (datos.email || '').trim();
|
||||
if (emailVal && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(emailVal)) {
|
||||
mostrarToast('El correo electrónico no es válido. Ej: nombre@dominio.com.', 'danger'); return;
|
||||
}
|
||||
// ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
// Normalizar teléfono: anteponer prefijo seleccionado
|
||||
const prefijo = document.getElementById('pac-tel-prefijo').value || '57';
|
||||
let tel = (datos.telefono || '').replace(/[^0-9+]/g, '');
|
||||
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;
|
||||
}
|
||||
|
||||
const r = await fetch('api/lab/save_paciente.php', {
|
||||
method: 'POST',
|
||||
|
||||
Reference in New Issue
Block a user