-
Notifications
You must be signed in to change notification settings - Fork 0
/
validateScore.js
147 lines (121 loc) · 3.74 KB
/
validateScore.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
$(document).ready(function(){
// ====================================================== //
var jVal = {
'scoreDate' : function (){
$('body').append('<div id="birthInfo" class="info"></div>');
var birthInfo = $('#birthInfo');
var ele = $('#scoreDate');
var pos = ele.offset();
birthInfo.css({
top: pos.top-3,
left: pos.left+ele.width()+15
});
var pattern = new RegExp(/\b\d{1,2}[\/-]\d{1,2}[\/-]\d{4}\b/);
if(!pattern.test(ele.val())) {
jVal.errors = true;
birthInfo.removeClass('correct').addClass('error').html('← must be format mm/dd/yyyy').show();
ele.removeClass('normal').addClass('wrong');
} else {
birthInfo.removeClass('error').addClass('correct').html('√').show();
ele.removeClass('wrong').addClass('normal');
}
},
'validateSplit' : function() {
$('body').append('<div id="splitInfo" class="info"></div>');
var splitInfo = $('#splitInfo');
var ele = $('#split');
var pos = ele.offset();
splitInfo.css({
top: pos.top-3,
left: pos.left+ele.width()+15
});
if (ele.val() == "") {
jVal.split = false;
return true;
}
var pattern = new RegExp(/\b\d{1}[:]\d{2}\b/);
if(!pattern.test(ele.val())) {
jVal.errors = true;
splitInfo.removeClass('correct').addClass('error').html('← must be format m:ss').show();
ele.removeClass('normal').addClass('wrong');
} else {
splitInfo.removeClass('error').addClass('correct').html('√').show();
ele.removeClass('wrong').addClass('normal');
}
},
'validateDistance' : function() {
$('body').append('<div id="distanceInfo" class="info"></div>');
var distanceInfo = $('#distanceInfo');
var ele = $('#distance');
var pos = ele.offset();
distanceInfo.css({
top: pos.top-3,
left: pos.left+ele.width()+15
});
if (ele.val() == "") {
jVal.distance = false;
return true;
}
var pattern = new RegExp(/\b\d{1,7}\b/);
if(!pattern.test(ele.val())) {
jVal.errors = true;
distanceInfo.removeClass('correct').addClass('error').html('← must be format dddd').show();
ele.removeClass('normal').addClass('wrong');
} else {
distanceInfo.removeClass('error').addClass('correct').html('√').show();
ele.removeClass('wrong').addClass('normal');
}
},
'validateTime' : function() {
$('body').append('<div id="timeInfo" class="info"></div>');
var info = $('#timeInfo');
var ele = $('#time');
var pos = ele.offset();
info.css({
top: pos.top-3,
left: pos.left+ele.width()+15
});
if (ele.val() == "") {
jVal.distance = false;
return true;
}
var pattern = new RegExp(/\b\d{1}[:]\d{2}\b/);
if(!pattern.test(ele.val())) {
jVal.errors = true;
info.removeClass('correct').addClass('error').html('← must be format dddd').show();
ele.removeClass('normal').addClass('wrong');
} else {
info.removeClass('error').addClass('correct').html('√').show();
ele.removeClass('wrong').addClass('normal');
}
},
'sendIt' : function (){
if(!jVal.errors) {
$('#newScore').submit();
}
},
'setToday' : function() {
var ele = $('#scoreDate');
var date = new Date();
var month = date.getMonth() + 1;
var days = date.getDate();
var year = date.getFullYear();
ele.val(month + "/" + days + "/" + year);
}
};
jVal.setToday();
// ====================================================== //
$('#send').click(function (){
var obj = $.browser.webkit ? $('body') : $('html');
obj.animate({ scrollTop: $('#newScore').offset().top }, 750, function (){
jVal.errors = false;
jVal.scoreDate();
jVal.validateSplit();
jVal.validateDistance();
jVal.sendIt();
});
return false;
});
$('#scoreDate').change(jVal.scoreDate);
// ====================================================== //
});