-
Notifications
You must be signed in to change notification settings - Fork 0
/
signup_js.js
69 lines (61 loc) · 1.59 KB
/
signup_js.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
var k=0;
function ajaxmatch(e)
{
let par = "name=" + username.value;
let xhr = new XMLHttpRequest();
xhr.open("POST", 'usercheck.php');
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhr.onload = function () {
if (this.status == 200) {
let response = this.responseText;
if(response.trim() == "true") {
username.style.border = "2px solid red";
k++;
}
else {
username.style.border = "2px solid green";
k = 0;
}
}
}
xhr.send(par);
}
function validation(e){
let f=0;
let inputs =document.querySelectorAll(".inputvalue");
inputs.forEach(input=>{
if(!input.value)
{
input.style.border="2px solid red";
f++;
}
else
input.style.border="none";
});
if(k){
username.style.border="2px solid red";
}
let mail=document.getElementById("mail");
let cmail =document.getElementById("cmail");
var patt=/^(([^<>()\[\]\\.,;:\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(!(mail.value).match(patt))
{
mail.style.border="2px solid red";
f++;
}
else
mail.style.border="none";
if((mail.value)!==(cmail.value)){
cmail.style.border="2px solid red";
f++;
}
else
cmail.style.border="none";
if(f||k){
e.preventDefault();
}
}
const form= document.querySelector(".myform");
form.addEventListener("submit",validation);
const username= document.getElementById("user");
username.addEventListener("keyup",ajaxmatch);