]> Dogcows Code - chaz/p5-CGI-Ex/blobdiff - lib/CGI/Ex/validate.js
CGI::Ex 2.32
[chaz/p5-CGI-Ex] / lib / CGI / Ex / validate.js
index 388f6739d8277700c5752e80fe700d836619dc92..7b469115ba07c99fc76b2498ccf5f64454201544 100644 (file)
@@ -1,4 +1,4 @@
-// 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
 
@@ -310,7 +310,10 @@ function v_validate_buddy (form, field, field_val, val_hash, ifs_match) {
  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();
@@ -509,10 +512,8 @@ function v_check_type (value, type, field, form) {
  } 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;
@@ -832,7 +833,7 @@ document.validate = function (form, val_hash) {
  }
 
  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]) {
@@ -948,7 +949,9 @@ document.check_form = function (form, val_hash) {
    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);
   }
  }
 
@@ -960,9 +963,10 @@ document.check_form = function (form, val_hash) {
  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'];
@@ -997,8 +1001,8 @@ function v_el_attach (el, fvs, form, val_hash) {
    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;
This page took 0.01841 seconds and 4 git commands to generate.