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
+9 -2
View File
@@ -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'] ?? '');
+12 -2
View File
@@ -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 = '<i class="fas fa-calendar-check me-1"></i>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 = '<i class="fas fa-calendar-check me-1"></i>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;
}
}
+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', {