-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidation.js
165 lines (110 loc) · 3.43 KB
/
validation.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
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
function form1Validate(){
var fname = document.forms["form1"]["urName"].value;
var pswrd= document.getElementById('pd').value;
var cpswd = document.getElementById('cpd').value;
var email1 = document.forms["form1"]["email"].value;
if(isAlphebatic(fname))
if(emailValidation(email1))
if(ispassword(pswrd))
if(iscpassword(cpswd,pswrd))
{
return true;
}
else return false;
else return false;
else return false;
else return false;
}
function form2Validate(){
var fname = document.forms["form2"]["urName"].value;
var contact =document.forms["form2"]["number"].value;
var email1 = document.forms["form2"]["email"].value;
if(isAlphebatic(fname))
if(emailValidation(email1))
if(isNumeric(contact))
{
return true;
}
else return false;
else return false;
else return false;
}
function isEmpty(elemValue,field) {
if(elemValue == ""|| elemValue == "NULL"){
alert("You can't have "+field+" field empty");
return true;
}
else
return false;
}
function isAlphebatic(elemValue) {
if (!isEmpty(elemValue,"Name"))
{ var exp=/^[a-zA-Z]+$/;
if (elemValue.match(exp)){
return true;
}
else{
alert("Enter only Alphabetic Characters for your First Name");
return false;
}
}
else
return false;
}
function isNumeric(elemValue){
if(!isEmpty(elemValue,"Contact Number")) {
var num=/^[0-9]+$/;
if (elemValue.match(num)) {
return true;
}
else{
alert("Enter only numeric characters for contact number");
return false;
}}
else
return false;
}
function ispassword(elemValue) {
var pd = /^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#\$%\^&\*\}\{\(\)\+\-])/
if (!isEmpty(elemValue,"Password")) {
if (elemValue.length >= 8) {
if (elemValue.match(pd)) {
return true;
}
else {
alert("Enter only uppercase,lowercase,numeric characters and a special character");
return false;
}
}
else
alert("Length should be atleast 8 in password field");
}
else
return false;
}
function iscpassword(elemValue,yoo) {
if (!isEmpty(elemValue,"Retype Password")) {
if(elemValue==yoo){
return true;
}
else{
alert("Password and Retype Password fields should be same");
return false;
}}
else
return false;
}
function emailValidation(elemValue){
if(!isEmpty(elemValue, "Email Address")){
var atops = elemValue.indexOf("@");
var dotops = elemValue.indexOf(".");
if(atops < 1 || dotops+2 >= elemValue.length || atops +2 >dotops){
alert("Enter a valid Email Address");
return false;
}
else return true;
}
else{
return false;
}
}