summaryrefslogtreecommitdiff
path: root/js/login.js
blob: d51be90e465c75139723d0db523aab859c606241 (plain)
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 USERNAME_INPUT = document.getElementById("username");
const USERNAME_ICON_CANCEL = document.getElementById("icon-cancel__username");
const USERNAME_ICON_CHECK = document.getElementById("icon-check__username");
const USERNAME_INPUT_ERROR = document.getElementById("input-error__username");
const PASSWORD = document.getElementById("password");
const PASSWORD_ICON_CANCEL = document.getElementById("icon-cancel__password");
const PASSWORD_ICON_CHECK = document.getElementById("icon-check__password");
const PASSWORD_INPUT_ERROR = document.getElementById("input-error__password");

USERNAME_INPUT.addEventListener('input', validate_username);
PASSWORD.addEventListener('input', validate_password);

function validate_username(e){
  const USERNAME = e.target.value;
  var valid_username = /^[a-zA-Z0-9\_\-]{4,16}$/.test(USERNAME);
  if(valid_username){
    USERNAME_ICON_CHECK.style.display = "block";
    USERNAME_ICON_CANCEL.style.display = "none";
    USERNAME_INPUT_ERROR.style.display = "none";
  }
  if(!valid_username){
    USERNAME_ICON_CHECK.style.display = "none";
    USERNAME_ICON_CANCEL.style.display = "block";
    USERNAME_INPUT_ERROR.style.display = "block";
  }
}
function validate_password(e){
  const PASSWORD = e.target.value;
  var valid_password = /^.{4,12}$/.test(PASSWORD);
  if(valid_password){
    PASSWORD_ICON_CHECK.style.display = "block";
    PASSWORD_ICON_CANCEL.style.display = "none";
    PASSWORD_INPUT_ERROR.style.display = "none";
  }
  if(!valid_password){
    PASSWORD_ICON_CHECK.style.display = "none";
    PASSWORD_ICON_CANCEL.style.display = "block";
    PASSWORD_INPUT_ERROR.style.display = "block";
  }
}