-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidation.js
More file actions
54 lines (46 loc) · 1.88 KB
/
validation.js
File metadata and controls
54 lines (46 loc) · 1.88 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
54
function validateForm() {
var namePattern = /^[A-Za-z\s.'-]+$/;
var name = document.getElementById('name').value;
if (!namePattern.test(name)) {
alert('Please enter a valid name.');
return false;
}
var usernamePattern = /\s/;
var username = document.getElementById('username').value;
if (usernamePattern.test(username)) {
alert('Whitespace is not allowed in username.');
return false;
}
var emailPattern = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
var email = document.getElementById('email').value;
if (!emailPattern.test(email)) {
alert('Please enter a valid email.');
return false;
}
var passwordPattern = /^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#$%\^&\*])(?=.{8,})/;
var password = document.getElementById('password').value;
if (!passwordPattern.test(password)) {
alert('Password must be at least 8 characters long and contain at least one uppercase letter, one lowercase letter, one number, and one special character.');
return false;
}
var confirmPassword = document.getElementById('confirm-password').value;
if (password !== confirmPassword) {
alert('Confirm password does not match.');
return false;
}
return true;
}
function validatePassword() {
var passwordPattern = /^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#$%\^&\*])(?=.{8,})/;
var password = document.getElementById('password').value;
if (!passwordPattern.test(password)) {
alert('Password must be at least 8 characters long and contain at least one uppercase letter, one lowercase letter, one number, and one special character.');
return false;
}
var confirmPassword = document.getElementById('confirm-password').value;
if (password !== confirmPassword) {
alert('Confirm password does not match.');
return false;
}
return true;
}