-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvalidation8.js
29 lines (25 loc) · 1.04 KB
/
validation8.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
function validateForm() {
const name = document.getElementById("name").value;
const password = document.getElementById("password").value;
// Validate Name
// name contains only alphabets: The regular expression /^[A-Za-z]+$/
// checks if the input string (name) consists of only uppercase (A-Z) or
// lowercase (a-z) alphabetic characters, and nothing else.
// ^ asserts the start of the string.
// [A-Za-z] matches any alphabet (uppercase or lowercase).
// + ensures that there is at least one character.
// $ asserts the end of the string.
// name has a minimum length of 6 characters: name.length < 6 checks if the
// length of the string name is less than 6.
if (!/^[A-Za-z]+$/.test(name) || name.length < 6) {
alert("Name must contain only alphabets and be at least 6 characters long.");
return false;
}
// Validate Password
if (password.length < 6) {
alert("Password must be at least 6 characters long.");
return false;
}
alert("Validation successful!");
return true;
}