-// Copyright 2008 - Paul Seamons - $Revision: 1.81 $
+// Copyright 2008 - Paul Seamons - $Revision: 1.18 $
// Distributed under the Perl Artistic License without warranty
// See perldoc CGI::Ex::Validate for usage
for (var i = 0; i < values.length; i++) {
if (typeof(values[i]) == 'undefined') continue;
var orig = values[i];
- if (! field_val.do_not_trim) values[i] = values[i].replace(/^\s+/,'').replace(/\s+$/,'');
+ if (! field_val.do_not_trim) {
+ values[i] = values[i].replace(/^\s+/,'');
+ if (v_event != 'change') values[i] = values[i].replace(/\s+$/,'');
+ }
if (field_val.trim_control_chars) values[i] = values[i].replace(/\t/g,' ').replace(/[\x00-\x1F]/g,'');
if (field_val.to_upper_case) values[i] = values[i].toUpperCase();
if (field_val.to_lower_case) values[i] = values[i].toLowerCase();
} else if (type == 'LOCAL_PART') {
if (typeof(value) == 'undefined' || ! value.length) return 0;
if (typeof(v_local_part) != 'undefined') return (value.match(v_local_part) ? 1 : 0);
- if (value.match(/[^a-z0-9.\-!&+]/)) return 0;
- if (value.match(/^[.\-]/)) return 0;
- if (value.match(/[.\-&]$/)) return 0;
- if (value.match(/(\.-|-\.|\.\.)/)) return 0;
+ // ignoring all valid quoted string local parts
+ if (value.match(/[^\w.~!\#\$%\^&*\-=+?]/)) return 0;
} else if (type == 'IP') {
if (! value) return 0;
}
var f = val_hash['group set_all_hook'] || document.validate_set_all_hook;
- if (f) f(err_obj);
+ if (f) f(err_obj, val_hash, form);
var field = err_obj.first_field();
if (field && form[field]) {
if (k == 'extend') continue; // Protoype Array()
var el = form[k];
if (! el) return v_error("No form element by the name "+k);
- v_el_attach(el, h[k], form, val_hash);
+ var _change = !types.change ? 0 : typeof(types.change) == 'object' ? types.change[k] : 1;
+ var _blur = !types.blur ? 0 : typeof(types.blur) == 'object' ? types.blur[k] : 1;
+ v_el_attach(el, h[k], form, val_hash, _change, _blur);
}
}
if (types.load) { v_event = 'load'; document.validate(form) }
}
-function v_el_attach (el, fvs, form, val_hash) {
+function v_el_attach (el, fvs, form, val_hash, _change, _blur) {
+ if (!_change && !_blur) return;
if (! el.type) {
- if (el.length) for (var i = 0; i < el.length; i++) v_el_attach(el[i], fvs, form, val_hash);
+ if (el.length) for (var i = 0; i < el.length; i++) v_el_attach(el[i], fvs, form, val_hash, _change, _blur);
return;
}
var types = val_hash['group onevent'];
v_inline_error_set(k, e[k], val_hash, form);
}
};
- if (types.blur) el.onblur = func;
- if (types.change && ! (''+el).match(/HTMLCollection/)) { // find better way on opera
+ if (_blur) el.onblur = func;
+ if (_change && ! (''+el).match(/HTMLCollection/)) { // find better way on opera
var type = el.type ? el.type.toLowerCase() : '';
if (type.match(/(password|text|textarea)/)) el.onkeyup = func;
else if (type.match(/(checkbox|radio)/)) el.onclick = func;