Skip to content

Commit 6ceecb8

Browse files
committed
Field length validation
1 parent eb2e896 commit 6ceecb8

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

web/js/_settings.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ App.Constants.SUSPENDED_YES = 'yes';
2121
App.Constants.DNS_TEMPLATES = {'default': 'Default'};
2222

2323
// Settings
24+
App.Settings.FIELD_MAX_LEN = 32;
25+
App.Settings.DAY_MAX_LEN = 2;
26+
App.Settings.MONTH_MAX_LEN = 2;
27+
App.Settings.WDAY_MAX_LEN = 2;
28+
App.Settings.HOURS_MAX_LEN = 2;
29+
App.Settings.MINUTE_MAX_LEN = 2;
2430
App.Settings.USER_VISIBLE_NS = 2;
2531
App.Settings.NS_MIN = 2;
2632
App.Settings.NS_MAX = 8;

web/js/validators.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ App.Validate.Rule = {
3030
if ($(elm).val().trim() == '' || $(elm).val().search(/[^a-zA-Z_]+/) != -1) {
3131
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' is invalid'};
3232
}
33+
if ($(elm).val().trim() == '' || $(elm).val().length > App.Settings.FIELD_MAX_LEN) {
34+
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' too long'};
35+
}
3336
}
3437
return {VALID: true};
3538
},
@@ -38,13 +41,19 @@ App.Validate.Rule = {
3841
if ($(elm).val().trim() == '') {
3942
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' is required'};
4043
}
44+
if ($(elm).val().trim() == '' || $(elm).val().length > App.Settings.FIELD_MAX_LEN) {
45+
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' too long'};
46+
}
4147
}
4248
return {VALID: true};
4349
},
4450
'username' : function(elm) {
4551
if ($(elm).val().trim() != '' && $(elm).val().search(/[^a-zA-Z_]+/) != -1) {
4652
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' is invalid'};
4753
}
54+
if ($(elm).val().trim() == '' || $(elm).val().length > App.Settings.FIELD_MAX_LEN) {
55+
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' too long'};
56+
}
4857
return {VALID: true};
4958
},
5059
'required' : function(elm) {
@@ -69,18 +78,25 @@ App.Validate.Rule = {
6978
if ($(elm).val().trim() != '' && $(elm).val().search(/[^a-zA-Z]+/) != -1) {
7079
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' must contain only letters without spaces or other symbols'};
7180
}
81+
if ($(elm).val().trim() == '' || $(elm).val().length > App.Settings.FIELD_MAX_LEN) {
82+
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' too long'};
83+
}
7284
return {VALID: true};
7385
},
7486
'email': function(elm) {
7587
if ($(elm).val().search(/^\s*[\w\-\+_]+(\.[\w\-\+_]+)*\@[\w\-\+_]+\.[\w\-\+_]+(\.[\w\-\+_]+)*\s*$/) == -1) {
7688
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' not a valid email'};
7789
}
90+
if ($(elm).val().trim() == '' || $(elm).val().length > App.Settings.FIELD_MAX_LEN) {
91+
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' too long'};
92+
}
7893
return {VALID: true};
7994
},
8095
'ip': function(elm) {
8196
if ($(elm).val().trim() != '' && (/^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/).test($(elm).val()) == false) {
8297
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' not a valid IP value'};
8398
}
99+
84100
return {VALID: true};
85101
},
86102
'domain': function(elm) {
@@ -93,12 +109,18 @@ App.Validate.Rule = {
93109
if ($(elm).val().trim() != '' && (/^([a-z0-9\.])*[a-z0-9][a-z0-9\-]+[a-z0-9](\.[a-z]{2,4})+$/).test($(elm).val()) == false) {
94110
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' not a valid NS name'};
95111
}
112+
if ($(elm).val().trim() == '' || $(elm).val().length > App.Settings.FIELD_MAX_LEN) {
113+
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' too long'};
114+
}
96115
return {VALID: true};
97116
},
98117
'cronminute': function(elm) {
99118
if ($(elm).val().trim() != '' && $(elm).val().search(/[^0-9\/\*-,]+/) != -1) {
100119
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' wrong minute value'};
101120
}
121+
if ($(elm).val().trim() == '' || $(elm).val().length > App.Settings.MINUTE_MAX_LEN) {
122+
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' invalid'};
123+
}
102124
return {VALID: true};
103125
},
104126
'cronhour': function(elm) {
@@ -108,6 +130,9 @@ App.Validate.Rule = {
108130
if ($(elm).val().trim() != '' && $(elm).val().search(/[^0-9\/\*-,]+/) != -1) {
109131
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' wrong hour value'};
110132
}
133+
if ($(elm).val().trim() == '' || $(elm).val().length > App.Settings.HOURS_MAX_LEN) {
134+
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' invalid'};
135+
}
111136
return {VALID: true};
112137
},
113138
'cronwday': function(elm) {
@@ -117,6 +142,9 @@ App.Validate.Rule = {
117142
if ($(elm).val().trim() != '' && $(elm).val().search(/[^123456\/\*-,]+/) != -1) {
118143
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' wrong week day value'};
119144
}
145+
if ($(elm).val().trim() == '' || $(elm).val().length > App.Settings.WDAY_MAX_LEN) {
146+
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' invalid'};
147+
}
120148
return {VALID: true};
121149
},
122150
'cronmonth': function(elm) {
@@ -126,6 +154,9 @@ App.Validate.Rule = {
126154
if ($(elm).val().trim() != '' && $(elm).val().search(/[^0-9\/\*-,]+/) != -1) {
127155
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' wrong month value'};
128156
}
157+
if ($(elm).val().trim() == '' || $(elm).val().length > App.Settings.MONTH_MAX_LEN) {
158+
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' invalid'};
159+
}
129160
return {VALID: true};
130161
},
131162
'cronday': function(elm) {
@@ -135,6 +166,9 @@ App.Validate.Rule = {
135166
if ($(elm).val().trim() != '' && $(elm).val().search(/[^0-9\/\*-,]+/) != -1) {
136167
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' wrong day value'};
137168
}
169+
if ($(elm).val().trim() == '' || $(elm).val().length > App.Settings.DAY_MAX_LEN) {
170+
return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' invalid'};
171+
}
138172
return {VALID: true};
139173
}
140174
}

0 commit comments

Comments
 (0)