-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
54 lines (48 loc) · 1.57 KB
/
index.js
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Función para hacer scroll hacia arriba
function scrollToTop() {
window.scrollTo({top: 0, behavior: 'smooth'});
}
// Función para mostrar u ocultar el botón
function toggleButtonVisibility() {
const button = document.getElementById('volver-arriba');
const footer = document.querySelector('footer');
const footerRect = footer.getBoundingClientRect();
const footerVisible = footerRect.top <= window.innerHeight;
if (footerVisible) {
button.classList.add('visible');
} else {
button.classList.remove('visible');
}
}
// Añadir el evento scroll para verificar la visibilidad del botón
window.addEventListener('scroll', toggleButtonVisibility);
/* validaciones*/
const nombre = document.getElementById("name")
const email = document.getElementById("email")
const pass = document.getElementById("password")
const form = document.getElementById("form")
const parrafo = document.getElementById("warnings")
form.addEventListener("submit", e=>{
e.preventDefault()
let warnings = ""
let entrar = false
let regexEmail = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/
parrafo.innerHTML = ""
if(nombre.value.length <4){
warnings += `El nombre es muy corto <br>`
entrar = true
}
if(!regexEmail.test(email.value)){
warnings += `El email no es valido <br>`
entrar = true
}
if(pass.value.length < 8){
warnings += `La contraseña es muy corta <br>`
entrar = true
}
if(entrar){
parrafo.innerHTML = warnings
}else{
parrafo.innerHTML = "Enviado"
}
})