up
This commit is contained in:
@@ -26,8 +26,15 @@ try {
|
|||||||
$telVal = trim($datos['telefono'] ?? '');
|
$telVal = trim($datos['telefono'] ?? '');
|
||||||
if ($telVal !== '') {
|
if ($telVal !== '') {
|
||||||
$telDigits = preg_replace('/[^0-9]/', '', $telVal);
|
$telDigits = preg_replace('/[^0-9]/', '', $telVal);
|
||||||
if (!preg_match('/^(57)?3\d{9}$/', $telDigits)) {
|
// Número colombiano: 10 dígitos empezando en 3, o con prefijo 57
|
||||||
jsonError('El celular debe comenzar por 3 y tener 10 dígitos. Ej: 3001234567.');
|
$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'] ?? '');
|
$docVal = trim($datos['numero_documento'] ?? '');
|
||||||
|
|||||||
+12
-2
@@ -1717,11 +1717,21 @@ const agendaNueva = {
|
|||||||
// Validar teléfono si fue ingresado
|
// Validar teléfono si fue ingresado
|
||||||
const telRaw = document.getElementById('na-np-telefono').value.trim();
|
const telRaw = document.getElementById('na-np-telefono').value.trim();
|
||||||
if (telRaw) {
|
if (telRaw) {
|
||||||
|
const prefijo = document.getElementById('na-np-prefijo').value || '57';
|
||||||
const telDigits = telRaw.replace(/[^0-9]/g, '');
|
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.disabled = false;
|
||||||
btn.innerHTML = '<i class="fas fa-calendar-check me-1"></i>Agendar';
|
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;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-3
@@ -373,9 +373,18 @@ async function guardarPaciente() {
|
|||||||
if (tel.startsWith('+')) tel = tel.slice(1);
|
if (tel.startsWith('+')) tel = tel.slice(1);
|
||||||
if (tel.length === 10) tel = prefijo + tel;
|
if (tel.length === 10) tel = prefijo + tel;
|
||||||
datos.telefono = tel || null;
|
datos.telefono = tel || null;
|
||||||
// Validar formato de celular
|
// Validar formato: colombiano (57) exige iniciar en 3 con 10 dígitos; otros países solo longitud
|
||||||
if (datos.telefono && !/^(57)?3\d{9}$/.test(datos.telefono)) {
|
if (datos.telefono) {
|
||||||
mostrarToast('El celular debe comenzar por 3 y tener 10 dígitos. Ej: 3001234567.', 'danger'); return;
|
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', {
|
const r = await fetch('api/lab/save_paciente.php', {
|
||||||
|
|||||||
Reference in New Issue
Block a user