-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathValidationJs.js
45 lines (39 loc) · 1.4 KB
/
ValidationJs.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
function required1(obj, str, errorid) {
if (obj.value == "") {
document.getElementById(errorid).innerHTML = str;
obj.style.borderColor = "red";
document.getElementById(errorid).style.color = "red";
obj.focus();
}
else {
document.getElementById(errorid).innerHTML = "";
obj.style.borderColor = "black";
}
}
function validate(obj, type, errorid) {
var phoneno = /^\d{10}$/;
var email = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*$/;
if (type == "Phone") {
if (obj.value.match(phoneno)) {
document.getElementById(errorid).innerHTML = "";
obj.style.borderColor = "black";
return true;
} else {
document.getElementById(errorid).innerHTML = "Enter Valid Phone Number";
obj.style.borderColor = "red";
document.getElementById(errorid).style.color = "red";
obj.focus();
}
}else if (type == "email") {
if (obj.value.match(phoneno)) {
document.getElementById(errorid).innerHTML = "";
obj.style.borderColor = "black";
return true;
} else {
document.getElementById(errorid).innerHTML = "Enter Valid Phone Number";
obj.style.borderColor = "red";
document.getElementById(errorid).style.color = "red";
obj.focus();
}
}
}