-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassignment6.js
More file actions
164 lines (131 loc) · 4.33 KB
/
assignment6.js
File metadata and controls
164 lines (131 loc) · 4.33 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
$(document).ready(function(){
$("#state").focus(function(){
$("#stateHint").append("Use a two letter abreviation");
}).blur(function(){
$("#stateHint").empty();
});
$("#zipCode").focus(function(){
$("#zipHint").append("Use a 5 digit Zip Code");
}).blur(function(){
$("#zipHint").empty();
});
$("#phone").focus(function(){
$("#phoneHint").append("Numbers Only - No Spaces or Dashes");
}).blur(function(){
$("#phoneHint").empty();
});
$("#email").focus(function(){
$("#emailHint").append("Example - john@doe.com");
}).blur(function(){
$("#emailHint").empty();
});
$("#card_number").focus(function(){
$("#cardHint").append("Numbers Only - No Spaces or Dashes");
}).blur(function(){
$("#cardHint").empty();
});
var errors = 0;
$("#custForm").submit(function(event){
var fnamePattern = /^[a-zA-Z]+(([\'\,\.\-][a-zA-Z])?[a-zA-Z]*)*$/i;
if(!fnamePattern.test($("#firstName").val())){
$("#fnError").append("Must contain only letters and spaces between 2 and 20 characters");
errors += 1;
}
if(errors > 0){
$("#custForm").prepend("Please Edit the marked fields");
event.preventDefault();
}
});
$("#custForm").submit(function(event){
var lnamePattern = /^[a-zA-Z]+(([\'\,\.\-][a-zA-Z])?[a-zA-Z]*)*$/i;
if(!lnamePattern.test($("#lastName").val())){
$("#lnError").append("Must contain only letters and spaces between 2 and 20 characters");
errors += 1;
}
if(errors > 0){
$("#custForm").prepend("Please Edit the marked fields");
event.preventDefault();
}
});
$("#custForm").submit(function(event){
var cityPattern = /^[a-z ,.'-]+$/i;
if(!cityPattern.test($("#city").val())){
$("#cityError").append("Must contain only letters and spaces between 2 and 20 characters");
errors += 1;
}
if(errors > 0){
$("#custForm").prepend("Please Edit the marked fields");
event.preventDefault();
}
});
$("#custForm").submit(function(event){
var address1Pattern = /^([1-zA-Z0-1@.\s]{1,255})$/i;
if(!address1Pattern.test($("#address1").val())){
$("#address1Error").append("Must contain only letters, numbers, and spaces between 2 and 20 characters");
errors += 1;
}
});
$("#custForm").submit(function(event){
var statePattern = /^(?:(A[KLRZ]|C[AOT]|D[CE]|FL|GA|HI|I[ADLN]|K[SY]|LA|M[ADEINOST]|N[CDEHJMVY]|O[HKR]|P[AR]|RI|S[CD]|T[NX]|UT|V[AIT]|W[AIVY]))$/i;
if(!statePattern.test($("#state").val())){
$("#stateError").append("Must contain a valid two-letter State abbreviation");
errors += 1;
}
});
$("#custForm").submit(function(event){
var zipPattern = /^\d{5}-\d{4}|\d{5}|[A-Z]\d[A-Z] \d[A-Z]\d$/i;
if(!zipPattern.test($("#zipCode").val())){
$("#zipError").append("Must contain a 5 number Zip Code!");
errors += 1;
}
});
$("#custForm").submit(function(event){
var phonePattern = /^\D?(\d{3})\D?\D?(\d{3})\D?(\d{4})$/i;
if(!phonePattern.test($("#phone").val())){
$("#phoneError").append("Must contain a 10 digit number with no spaces or dashes");
errors += 1;
}
});
var selectedVal = "";
var selected = $("input[type='radio'][name='card_type2']:checked");
if (selected.length > 0){
selectedVal = selected.val();
if(selectedVal != "None"){
$("#custForm").submit(function(event){
var cardPattern = /^(\d{4}[- ]){3}\d{4}|\d{16}$/i;
if(!cardPattern.test($("#cardNumber").val())){
$("#cardError").append("Must contain a 13-16 digit number with no spaces or dashes");
errors += 1;
}
});
$("#custForm").submit(function(event){
if($("#expirationMonth").val() == "month"){
$("#monthError").append("Must select a month");
errors += 1;
}
});
$("#custForm").submit(function(event){
if($("#expirationYear").val() == "year"){
$("#yearError").append("Must select a year");
errors += 1;
}
});
}
}
else if($("input[name=card_type2]:checked").val() = "None"){
}
$("#custForm").submit(function(event){
var emailPattern = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
if(!emailPattern.test($("#email").val())){
$("#emailError").append("Must be a valid Email Address!");
errors += 1;
}
if(errors > 0){
event.preventDefault();
}
});
if(errors > 0){
event.preventDefault();
location.reload();
}
});