Dima Malishev 14 лет назад
Родитель
Сommit
6ceecb886e
2 измененных файлов с 40 добавлено и 0 удалено
  1. 6 0
      web/js/_settings.js
  2. 34 0
      web/js/validators.js

+ 6 - 0
web/js/_settings.js

@@ -21,6 +21,12 @@ App.Constants.SUSPENDED_YES         = 'yes';
 App.Constants.DNS_TEMPLATES         = {'default': 'Default'};
 
 // Settings
+App.Settings.FIELD_MAX_LEN      = 32;
+App.Settings.DAY_MAX_LEN        = 2;
+App.Settings.MONTH_MAX_LEN      = 2;
+App.Settings.WDAY_MAX_LEN       = 2;
+App.Settings.HOURS_MAX_LEN      = 2;
+App.Settings.MINUTE_MAX_LEN     = 2;
 App.Settings.USER_VISIBLE_NS    = 2;
 App.Settings.NS_MIN             = 2;
 App.Settings.NS_MAX             = 8;

+ 34 - 0
web/js/validators.js

@@ -30,6 +30,9 @@ App.Validate.Rule = {
             if ($(elm).val().trim() == '' || $(elm).val().search(/[^a-zA-Z_]+/) != -1) {
                 return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' is invalid'};
             }
+            if ($(elm).val().trim() == '' || $(elm).val().length > App.Settings.FIELD_MAX_LEN) {
+                return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' too long'};
+            }
         }
         return {VALID: true};
     },
@@ -38,6 +41,9 @@ App.Validate.Rule = {
             if ($(elm).val().trim() == '') {
                 return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' is required'};
             }
+            if ($(elm).val().trim() == '' || $(elm).val().length > App.Settings.FIELD_MAX_LEN) {
+                return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' too long'};
+            }
         }
         return {VALID: true};
     },
@@ -45,6 +51,9 @@ App.Validate.Rule = {
         if ($(elm).val().trim() != '' && $(elm).val().search(/[^a-zA-Z_]+/) != -1) {
             return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' is invalid'};
         }
+        if ($(elm).val().trim() == '' || $(elm).val().length > App.Settings.FIELD_MAX_LEN) {
+            return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' too long'};
+        }
         return {VALID: true};
     },
     'required' : function(elm) {
@@ -69,18 +78,25 @@ App.Validate.Rule = {
         if ($(elm).val().trim() != '' && $(elm).val().search(/[^a-zA-Z]+/) != -1) {
             return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' must contain only letters without spaces or other symbols'};
         }
+        if ($(elm).val().trim() == '' || $(elm).val().length > App.Settings.FIELD_MAX_LEN) {
+            return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' too long'};
+        }
         return {VALID: true};
     },
     'email':      function(elm) {
         if ($(elm).val().search(/^\s*[\w\-\+_]+(\.[\w\-\+_]+)*\@[\w\-\+_]+\.[\w\-\+_]+(\.[\w\-\+_]+)*\s*$/) == -1) {
             return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' not a valid email'};
         }
+        if ($(elm).val().trim() == '' || $(elm).val().length > App.Settings.FIELD_MAX_LEN) {
+            return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' too long'};
+        }
         return {VALID: true};
     },
     'ip':         function(elm) {        
         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) {
             return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' not a valid IP value'};
         }
+        
         return {VALID: true};
     },
     'domain':         function(elm) {        
@@ -93,12 +109,18 @@ App.Validate.Rule = {
         if ($(elm).val().trim() != '' && (/^([a-z0-9\.])*[a-z0-9][a-z0-9\-]+[a-z0-9](\.[a-z]{2,4})+$/).test($(elm).val()) == false) {
             return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' not a valid NS name'};
         }
+        if ($(elm).val().trim() == '' || $(elm).val().length > App.Settings.FIELD_MAX_LEN) {
+            return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' too long'};
+        }
         return {VALID: true};
     },
     'cronminute':         function(elm) { 
         if ($(elm).val().trim() != '' && $(elm).val().search(/[^0-9\/\*-,]+/) != -1) {
             return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' wrong minute value'};
         }
+        if ($(elm).val().trim() == '' || $(elm).val().length > App.Settings.MINUTE_MAX_LEN) {
+            return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' invalid'};
+        }
         return {VALID: true};
     },
     'cronhour':         function(elm) {   
@@ -108,6 +130,9 @@ App.Validate.Rule = {
         if ($(elm).val().trim() != '' && $(elm).val().search(/[^0-9\/\*-,]+/) != -1) {
             return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' wrong hour value'};
         }
+        if ($(elm).val().trim() == '' || $(elm).val().length > App.Settings.HOURS_MAX_LEN) {
+            return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' invalid'};
+        }
         return {VALID: true};
     },
     'cronwday':         function(elm) {  
@@ -117,6 +142,9 @@ App.Validate.Rule = {
         if ($(elm).val().trim() != '' && $(elm).val().search(/[^123456\/\*-,]+/) != -1) {
             return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' wrong week day value'};
         }
+        if ($(elm).val().trim() == '' || $(elm).val().length > App.Settings.WDAY_MAX_LEN) {
+            return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' invalid'};
+        }
         return {VALID: true};
     },
     'cronmonth':         function(elm) { 
@@ -126,6 +154,9 @@ App.Validate.Rule = {
         if ($(elm).val().trim() != '' && $(elm).val().search(/[^0-9\/\*-,]+/) != -1) {
             return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' wrong month value'};
         }
+        if ($(elm).val().trim() == '' || $(elm).val().length > App.Settings.MONTH_MAX_LEN) {
+            return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' invalid'};
+        }
         return {VALID: true};
     },
     'cronday':         function(elm) {  
@@ -135,6 +166,9 @@ App.Validate.Rule = {
         if ($(elm).val().trim() != '' && $(elm).val().search(/[^0-9\/\*-,]+/) != -1) {
             return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' wrong day value'};
         }
+        if ($(elm).val().trim() == '' || $(elm).val().length > App.Settings.DAY_MAX_LEN) {
+            return {VALID: false, ERROR: App.Validate.getFieldName(elm) + ' invalid'};
+        }
         return {VALID: true};
     }
 }