-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
executable file
·61 lines (48 loc) · 1.41 KB
/
script.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
const loginForm = document.getElementById('login-form');
const emailInp = document.getElementById('email-input');
const passInp = document.getElementById('password-input');
const submitBtn = document.getElementById('submit-btn');
login = {
username: '[email protected]',
password: 'password'
}
const now = new moment();
console.log(now);
//checking email and password
function checkRequired(input){
input.forEach(function(input){
if(input.value.trim()===''){
showError(input);
} else {
showSuccess(input);
}
});
}
//show success of input
function showSuccess(input){
input.className = 'input success'
}
//show failure of input
function showError(input, message){
input.className = 'input fail'
if(message !== ""){
input.placeholder = `${message}`
}
}
//check email
function checkEmail (email){
const regexp = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
if(regexp.test(email.value.trim())){
showSuccess(email);
} else{
emailInp.value="";
showError(email, 'Email not Valid')
}
}
//on submit button click
submitBtn.addEventListener('click', function(e){
e.preventDefault();
checkRequired([emailInp, passInp]);
checkEmail(emailInp);
location.assign("/dashboard/dashboard.html");
})