-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforma.js
40 lines (31 loc) · 1.09 KB
/
forma.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
const loginForm = document.getElementById('userForm');
const nameInput = document.getElementById('name');
const emailInput = document.getElementById('email');
const passwordInput = document.getElementById('password');
const emailError = document.getElementById('emailError');
const passwordError = document.getElementById('passwordError');
const nameError = document.getElementById('nameError');
const emailRegex = /^[^\s@]+@[^\s@]+.[^\s@]+$/;
const nameRegex = /^[A-Z].{2,}$/;
userForm.addEventListener('submit', function (e) {
e.preventDefault();
let isValid = true;
if(!nameRegex.test(nameInput.value)) {
nameError.textContent = 'Please enter a valid name';
isValid = false;
} else{
nameError.textContent = '';
}
if (!emailRegex.test(emailInput.value)) {
emailError.textContent = 'Please enter a valid email address';
isValid = false;
} else {
emailError.textContent = '';
}
if (passwordInput.value.length < 6) {
passwordError.textContent = 'Password must be at least 6 characters';
isValid = false;
} else {
passwordError.textContent = '';
}
});