-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
53 lines (38 loc) · 1.53 KB
/
script.js
File metadata and controls
53 lines (38 loc) · 1.53 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
document.getElementById("registrationForm").addEventListener("submit", function (e) {
e.preventDefault(); // Prevent form submission
const nameField = document.getElementById("name");
const passwordField = document.getElementById("password");
const nameError = document.getElementById("nameError");
const passwordError = document.getElementById("passwordError");
let isValid = true;
nameField.style.border = "";
passwordField.style.border = "";
nameError.textContent = "";
passwordError.textContent = "";
const name = nameField.value.trim();
if (name.length < 6) {
nameError.textContent = "Name must be at least 6 characters";
nameField.style.border = "2px solid red";
isValid = false;
}
if(!/^[a-zA-Z\s]+$/.test(name)){
nameError.textContent = "Contain only alphabets.";
nameField.style.border = "2px solid red";
isValid = false;
}
const password = passwordField.value.trim();
if (password.length < 6) {
passwordError.textContent = "Password must be at least 6 characters long.";
passwordField.style.border = "2px solid red";
isValid = false;
}
//var password = document.getElementById("password").value;
var confirmPassword = document.getElementById("confirmPassword").value;
// Check if the passwords match
if (password !== confirmPassword) {
alert("Passwords do not match. Please try again.");
}
if (isValid) {
alert("Form submitted successfully!");
}
});