-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathform_validation.html
More file actions
132 lines (81 loc) · 3.51 KB
/
Copy pathform_validation.html
File metadata and controls
132 lines (81 loc) · 3.51 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
<!DOCTYPE html>
<html>
<head>
<title>Learning Javascript</title>
<meta charset="utf-8" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<style>
#wrapper {
width: 600px;
margin: 0 auto;
font-family: helvetica;
font-size: 1.2em;
}
input {
width: 300px;
height: 30px;
padding: 5px;
border-radius: 5px;
font-size: 1.2em;
border: 1px solid grey;
margin-bottom: 10px;
}
label {
width: 200px;
float: left;
padding-top: 7px;
}
#submitButton {
height: 50px;
margin-left: 200px;
width: 100px;
}
#error {
color: red;
margin:20px;
}
</style>
</head>
<body>
<div id="wrapper">
<div id="error"></div>
<form id="validationForm">
<label id="email" for="email">Email</label>
<input name="email" />
<label id="phone" for="phone">Telephone</label>
<input name="phone" />
<label id="pass1" for="pass">Password</label>
<input name="pass" type="password" />
<label id="pass2" for="pass">Confirm Password</label>
<input name="pass" type="password" />
<input id="submitButton" type="submit" value="Submit" />
</form>
</div>
<script>
$("#validationForm").submit(function(event) {
var errorMessage="";
event.preventDefault();
function isValidEmailAddress(emailAddress) {
var pattern = new RegExp(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i);
return pattern.test(emailAddress);
};
if(!isValidEmailAddress($("#email").val())) {
errorMessage="<br />Please enter a valid email address";
}
if(!$.isNumeric($("#phone").val())) {
errorMessage=errorMessage+"<br />Please enter a valid phone number";
}
if($("#pass1").val() != $("#pass2").val()) {
errorMessage=errorMessage+"<br />Please enter matching passwords";
}
if (errorMessage=="") {
alert("Success!");
} else {
$("#error").html(errorMessage);
}
});
</script>
</body>
</html>