From 894fbf39d3986323d1b354a5ae8838ec35b60b9d Mon Sep 17 00:00:00 2001 From: Facundo Saucedo <43495919@terciariourquiza.edu.ar> Date: Mon, 25 May 2026 12:42:12 -0300 Subject: [PATCH] feat: implement user form with validation for username, age, and password --- ejercicio7/ejercicio7.js | 23 +++++++++++++++++++++++ ejercicio7/index.html | 10 +++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/ejercicio7/ejercicio7.js b/ejercicio7/ejercicio7.js index 6ce9e92..f2149f9 100644 --- a/ejercicio7/ejercicio7.js +++ b/ejercicio7/ejercicio7.js @@ -1 +1,24 @@ // Agregar aquí el código javascript + +const userForm = document.getElementById('userForm'); + +userForm.addEventListener('submit', (event) => { + event.preventDefault(); + const username = document.getElementById('username').value.trim(); + const age = parseInt(document.getElementById('age').value); + const password = document.getElementById('password').value; + if (username === '') { + alert('El nombre de usuario no puede estar vacío.'); + return; + } + if (isNaN(age) || age < 0 || age > 100) { + alert('La edad debe ser un número válido entre 0 y 100.'); + return; + } + if (password.length < 8) { + alert('La contraseña debe tener al menos 8 caracteres.'); + return; + } + alert('Formulario enviado correctamente.'); + userForm.reset(); +}); \ No newline at end of file diff --git a/ejercicio7/index.html b/ejercicio7/index.html index 205939a..86d1eda 100644 --- a/ejercicio7/index.html +++ b/ejercicio7/index.html @@ -8,7 +8,15 @@