-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontacto.js
More file actions
37 lines (29 loc) · 1.27 KB
/
Copy pathcontacto.js
File metadata and controls
37 lines (29 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
document.addEventListener("DOMContentLoaded", function () {
console.log("✅ Script de contacto cargado correctamente.");
const formulario = document.getElementById("contact-form");
if (formulario) {
formulario.addEventListener("submit", function (event) {
// event.preventDefault(); // Evita recargar la página
let nombre = document.getElementById("nombre").value.trim();
let apellido = document.getElementById("apellido").value.trim();
let email = document.getElementById("email").value.trim();
let mensaje = document.getElementById("mensaje").value.trim();
// Validaciones
if (!nombre || !apellido || !email || !mensaje) {
alert("⚠️ Por favor, completa todos los campos.");
return;
}
if (!validarEmail(email)) {
alert("⚠️ Ingresa un correo electrónico válido.");
return;
}
});
} else {
console.warn("⚠️ No se encontró el formulario con ID 'contact-form'.");
}
// Función para validar el correo electrónico
function validarEmail(email) {
const regex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return regex.test(email);
}
});