-
Notifications
You must be signed in to change notification settings - Fork 0
/
Js-SignUp.js
125 lines (95 loc) · 3.51 KB
/
Js-SignUp.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
const imgDiv = document.querySelector('.profile-pic-div');
const img = document.querySelector('#photo');
const file = document.querySelector('#file');
const email = document.querySelector('#email');
const btn = document.querySelector('.btn');
const fname = document.querySelector('#fname');
const lname = document.querySelector('#lname');
const phone = document.querySelector('#phone');
const pass = document.querySelector('#pass');
const gender = document.querySelector('#gender');
const submitbtn = document.querySelector('.btnsubmit');
file.addEventListener('change', function(){
const choosedFile = this.files[0];
if (choosedFile) {
const reader = new FileReader();
reader.addEventListener('load', function(){
img.setAttribute('src', reader.result);
});
reader.readAsDataURL(choosedFile);
}
});
function validateInput(){
var passLength = pass.value;
var phoneLength = phone.value;
if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email.value)))
{
errorMSG("emailError","You have entered an invalid email address!");
}
if ((/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email.value)))
{
errorMSG("emailError","");
}
if(!(/[a-zA-Z]/.test(pass.value)))
{
errorMSG("passError","Password must contain at least one letter and it must be of length 8!");
}
if((/[a-zA-Z]/.test(pass.value)))
{
errorMSG("passError","");
}
if((passLength.length<8))
{
errorMSG("passError","Password must contain at least one letter and it must be of length 8!");
}
if(!(passLength.length<8))
{
errorMSG("passError","");
}
if(!(phoneLength.length<10))
{
errorMSG("PhoneError","");
}
if(!(/^[0-9]*$/.test(phone.value)))
{
errorMSG("PhoneError","Phone number must contain digits only and must be of length 10!");
}
if((/^[0-9]*$/.test(phone.value)))
{
errorMSG("PhoneError","");
}
if((phoneLength.length<10))
{
errorMSG("PhoneError","Phone number must contain digits only and must be of length 10!");
}
if(!(/^[a-zA-Z]*$/.test(fname.value)))
{
errorMSG("fnameError","First Name must contain letters only!");
}
if((/^[a-zA-Z]*$/.test(fname.value)))
{
errorMSG("fnameError","");
}
if(!(/^[a-zA-Z]*$/.test(lname.value)))
{
errorMSG("lnameError","Last Name must contain letters only!");
}
if((/^[a-zA-Z]*$/.test(lname.value)))
{
errorMSG("lnameError","");
}
if((!(/^[a-zA-Z]*$/.test(lname.value))) || (!(/^[a-zA-Z]*$/.test(fname.value))) || (!(/^[0-9]*$/.test(phone.value))) || ((phoneLength.length<10)) || ((passLength.length<8)) || (!(/[a-zA-Z]/.test(pass.value))) || (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email.value))))
return false;
}
function errorMSG(id,value){
document.getElementById(id).innerText=value;
}
const togglePassword = document.querySelector('#togglePassword');
const password = document.querySelector('#pass');
togglePassword.addEventListener('click', function (e) {
// toggle the type attribute
const type = password.getAttribute('type') === 'password' ? 'text' : 'password';
password.setAttribute('type', type);
// toggle the eye slash icon
this.classList.toggle('fa-eye-slash');
});