valid = this.vstack[0].apply(this, this.vstack[1]);
if (valid !== true) {
- this.field.setAttribute('data-tooltip', _('Expecting %s').format(this.error));
+ this.field.setAttribute('data-tooltip', _('Expecting: %s').format(this.error));
this.field.setAttribute('data-tooltip-style', 'error');
this.field.dispatchEvent(new CustomEvent('validation-failure', { bubbles: true }));
return false;
return this.assert(this.factory.parseDecimal(this.value) <= +max, _('value smaller or equal to %f').format(max));
},
+ length: function(len) {
+ var val = '' + this.value;
+ return this.assert(val.length == +len,
+ _('value with %d characters').format(len));
+ },
+
rangelength: function(min, max) {
var val = '' + this.value;
return this.assert((val.length >= +min) && (val.length <= +max),
}
}
- return this.assert(false, _('one of:\n - %s'.format(errors.join('\n - '))));
+ var t = _('One of the following: %s');
+
+ return this.assert(false, t.format('\n - ' + errors.join('\n - ')));
},
and: function() {
},
neg: function() {
- return this.apply('or', this.value.replace(/^[ \t]*![ \t]*/, ''), arguments);
+ this.value = this.value.replace(/^[ \t]*![ \t]*/, '');
+
+ if (arguments[0].apply(this, arguments[1]))
+ return this.assert(true);
+
+ return this.assert(false, _('Potential negation of: %s').format(this.error));
},
list: function(subvalidator, subargs) {
day = +RegExp.$3,
days_in_month = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ];
- function is_leap_year(year) {
+ var is_leap_year = function(year) {
return ((!(year % 4) && (year % 100)) || !(year % 400));
}
- function get_days_in_month(month, year) {
+ var get_days_in_month = function(month, year) {
return (month === 2 && is_leap_year(year)) ? 29 : days_in_month[month - 1];
}