-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalid.gs
More file actions
109 lines (92 loc) · 2.5 KB
/
valid.gs
File metadata and controls
109 lines (92 loc) · 2.5 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
function validation(res){
var req = checkRequired(res);
var color = checkHexaColors(res.colorText, res.colorFill, res.colorBorder);
var num = checkNumber(res.borderRound);
if (req !== 'Ok')
return req;
else if (!checkEmailFormat(res.replyAddress))
return 'Wrong email format!';
else if (color !== 'Ok')
return color;
else if (num !== 'Ok')
return num;
else
return 'Ok';
}
function checkRequired(res){
var subject = !res.subject ? 1 : 0;
var replyAddress = !res.replyAddress ? 1 : 0;
var buttonTexts = !res.buttonTexts ? 1 : 0;
var result = subject + replyAddress + buttonTexts;
if(result === 0)
return 'Ok';
else{
var end;
if (result > 1)
end = ' fields!';
else
end = ' field!';
var errText = 'Empty '
if (subject === 1)
errText += 'Response Subject, ';
if (replyAddress === 1)
errText += 'Reply Address, ';
if (buttonTexts === 1)
errText += 'ButtonTexts, ';
return errText.substr(0, errText.length-2)+end;
}
}
function checkEmailFormat(email){
var regExpPattern = /\S+@\S+\.\S+/;
return regExpPattern.test(email);
}
function checkHexaColors(colorText, colorFill, colorBorder){
var text = !colorText ? 0 : (checkHexaColorFormat(colorText) ? 0 : 1);
var fill = !colorFill ? 0 : (checkHexaColorFormat(colorFill) ? 0 : 1);
var border = !colorBorder ? 0 : (checkHexaColorFormat(colorBorder) ? 0 : 1)
var result = text + fill + border;
if(result === 0)
return 'Ok';
else{
var end;
if (result > 1)
end = ' color fields!';
else
end = ' color field!';
var errText = 'Wrong hexa format in '
if (text === 1)
errText += 'Text, ';
if (fill === 1)
errText += 'Fill, ';
if (border === 1)
errText += 'Border, ';
return errText.substr(0, errText.length-2)+end;
}
}
function checkHexaColorFormat(color) {
var regExpPattern = /#[0-9,a-f,A-F]{6}$/;
return regExpPattern.test(color);
}
function checkNumber(number){
if(!number)
return 'Ok';
else{
if (!checkNumberFormat(number))
return 'Wrong Border Round number format!';
else if (!checkNumberRange(number))
return 'Border Round has to be between 1 and 10!';
else
return 'Ok';
}
}
function checkNumberFormat(number){
var regExpPattern = /^[0-9]*$/;
return regExpPattern.test(number);
}
function checkNumberRange(number){
var num = parseInt(number,10);
if (num > 0 && num < 11)
return true;
else
return false;
}