-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreateAccountJavaScript.js
70 lines (49 loc) · 1.83 KB
/
CreateAccountJavaScript.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
document.addEventListener("DOMContentLoaded", function () {
function getCurrentDate(){
const date = new Date();
let day = date.getDate();
let month = date.getMonth() + 1;
let year = date.getFullYear();
let currentDate = `${day}-${month}-${year}`;
const time = new Date();
let hour =time.getHours();
let minute =time.getMinutes();
let second = time.getSeconds();
let currentTime = `${hour}:${minute}:${second}`;
let dateAndTime = "Date:" + currentDate + "<br>Time: "+currentTime;
return dateAndTime;
}
setInterval(function() {
document.getElementById("time").innerHTML= getCurrentDate();
}, 1000);
window.validateForm = function () {
let x = document.forms["myForm"]["fname"].value;
if (x == "") {
alert("Name must be filled out");
return false;
}
}
function validateUsername(username) {
const regex = /^[a-zA-Z0-9]+$/;
return regex.test(username);
}
function validatePassword(password) {
const regex = /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{4,}$/;
return regex.test(password);
}
window.checkUserInfo = function(){
const usernameInput = document.getElementById('username');
const passwordInput = document.getElementById('pass');
const username = usernameInput.value.trim();
const password = passwordInput.value.trim();
if (!validateUsername(username)) {
alert('Invalid username! Please enter a valid username.');
return false;
}
if (!validatePassword(password)) {
alert('Invalid password! Password must be at least 4 characters long and contain at least one letter and one digit.');
return false;
}
return true;
}
});