-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverification.js
More file actions
196 lines (165 loc) · 4.68 KB
/
verification.js
File metadata and controls
196 lines (165 loc) · 4.68 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
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
var max_length;
var original;
function stillOriginal(parent){
return (original==parent.value);
}
function v_open(input,max_length_i){
if(input.value===''){
original = input.value;
}else{
original = input.innerHTML;
}
e('error_msg').innerHTML = '';
max_length = max_length_i;
}
function len(input,t){
input.onkeydown = function(e){
return len_keydown_ext(e,input,t);
};
}
function len_keydown_ext(e,input,t){
if(e.keyCode==8 || e.keyCode==46){
return true;
}else if(input.value.length<max_length){
document.getElementById('error_msg').innerHTML = (t?pass(input):'')+'<span>'+max_length+'</span>';
return true;
}else{
document.getElementById('error_msg').innerHTML = (t?pass(input):'')+'<span class=finish >'+max_length+'</span>';
return false;
}
}
function v_close(){
e('error_msg').innerHTML = '';
}
function words(parent,length){
var w_l = parent.value.split(' ').length;
if(w_l<length){
e('error_msg').innerHTML = '<span class=highlight_green >Word Summary: '+length+'</span>';
return true;
}else{
e('error_msg').innerHTML = '<span class=highlight >Word Summary: '+length+'</span>';
}
}
function email(input,type,v_flag){
if(input.value && !stillOriginal(input)){
if(/[0-9a-zA-Z]{3,10}@[0-9a-zA-Z]{3,10}\.(com|co\.za)/.test(input.value)){
v_close();
input.className = 'tick';
if(v_flag){
sendVerification(input.value,type,0);
}
return true;
}else{
e('error_msg').innerHTML = '<span class=highlight >Cannot detect email</span>';
input.className = 'cross';
}
}
}
function sendVerification(target,type,resend){
e('v_load').id = 'v_load_show';
var f = new FormData();
f.append('target',target);
f.append('type',type);
var res = sendform_2('verification.php'+(resend?'?resend=1':''),f);
res.onload = function(){
e('v_load_show').id = 'v_load';
if(res.responseText.includes('success')){
e('v_code').style.display = 'block';
alert(res.responseText);
}else if(res.responseText.includes('already been sent')){
e('v_code').style.display = 'block';
if(confirm(res.responseText + '. Click OK to resend')){
sendVerification(target,type,1);
}
}
};
}
function password_v(input){
if(input.value){
var not_strong = /^[a-z]*$/.test(input.value) || /^[0-9]*$/.test(input.value) || /^[A-Z]*$/.test(input.value) || /^[a-z0-9]*$/.test(input.value) || /^[a-zA-Z]*$/.test(input.value) || /^[A-Z0-9]*$/.test(input.value);
if(!not_strong && /^[a-z0-9A-Z]*$/.test(input.value) && input.value.length>4){
v_close();
input.className = 'tick';
return true;
}else{
e('error_msg').innerHTML = '<span class=highlight >for strong password include: small and capital letters, numbers and at least 5 characters</span>';
input.className = 'cross';
}
}
}
function pass(input){
if(/^[a-z]*$/.test(input.value) || /^[0-9]*$/.test(input.value) || /^[A-Z]*$/.test(input.value)){
return 'weak';
}else if(/^[a-z0-9]*$/.test(input.value) || /^[a-zA-Z]*$/.test(input.value) || /^[A-Z0-9]*$/.test(input.value)){
return 'moderate';
}else if(/^[a-z0-9A-Z]*$/.test(input.value)){
return 'strong';
}else{
return '';
}
}
function showPassword(parent,f){
if(f){
parent.type='text';
}else{
parent.type='password';
}
}
function website(parent){
if(parent.value && !stillOriginal(parent)){
if(/https:\/\/[a-z]*\.[0-9a-z]*\.(com|co\.za|.*)/.test(parent.value)){
v_close();
parent.className = 'tick';
return true;
}else{
e('error_msg').innerHTML = '<span class=highlight >Reqiure format example: https://www.productlists.co.za/my_link </span>';
parent.className = 'cross';
}
}
}
function auto_correct(list,type,parent){
if(parent.value){
var v = parent.value.toLowerCase();
if(v.length>2){
for(var a=0;a<list.length;a++){
if(list[a].toLowerCase().includes(v)){
parent.value = list[a];
e('error_msg').innerHTML = '<span class=highlight_green >Your '+type+'...</span>';
break;
}else if(a==(list.length-1)){
e('error_msg').innerHTML = '<span class=highlight_green >You have inserted a new '+type+'.</span>';
break;
}
}
parent.className = 'tick';
}
}
return true;
}
function general_field(parent){
if(parent.value && !stillOriginal(parent)){
if(parent.value.length>2){
if(/\w/.test(parent.value)){
parent.className = 'tick';
return true;
}else{
parent.className = 'cross';
e('error_msg').innerHTML = '<span class=highlight >use letters only</span>';
}
}else{
parent.className = 'cross';
e('error_msg').innerHTML = '<span class=highlight >too short</span>';
}
}
}
function digit_field(parent){
if(parent.value && !stillOriginal(parent)){
if(isNaN(parent.value)){
parent.className = 'cross';
e('error_msg').innerHTML = '<span class=highlight >insert number</span>';
}else{
parent.className = 'tick';
return true;
}
}
}