* Based upon CGI/Ex/Validate.pm v1.14 from Perl *
* For instructions on usage, see perldoc of CGI::Ex::Validate *
***----------------------------------------------------------------**/
-// $Revision: 1.41 $
+// $Revision: 1.42 $
function Validate () {
this.error = vob_error;
return values;
}
-function vob_add_error (errors,field,type,field_val,ifs_match) {
+function vob_add_error (errors,field,type,field_val,ifs_match,form) {
errors[errors.length] = new Array(field, type, field_val, ifs_match);
+ if (field_val['clear_on_error']) {
+ var el = form[field];
+ if (el) {
+ var type = el.type;
+ if (type && (type == 'hidden' || type == 'password' || type == 'text' || type == 'textarea' || type == 'submit'))
+ el.value = '';
+ }
+ }
}
/// this is where the main checking goes on
if (is_required && (typeof(_value) == 'undefined'
|| ((typeof(_value) == 'object' && _value.length == 0)
|| ! _value.length))) {
- this.add_error(errors, field, is_required, field_val, ifs_match);
+ this.add_error(errors, field, is_required, field_val, ifs_match, form);
return errors;
}
for (var i = 0; i < tests.length; i ++) {
var n = field_val[tests[i]];
if (n_values < n) {
- this.add_error(errors, field, tests[i], field_val, ifs_match);
+ this.add_error(errors, field, tests[i], field_val, ifs_match, form);
return errors;
}
}
for (var i = 0; i < tests.length; i ++) {
var n = field_val[tests[i]];
if (n_values > n) {
- this.add_error(errors, field, tests[i], field_val, ifs_match);
+ this.add_error(errors, field, tests[i], field_val, ifs_match, form);
return errors;
}
}
}
if ( (minmax == 'min' && n > 0)
|| (minmax == 'max' && n < 0)) {
- this.add_error(errors, field, tests[i], field_val, ifs_match);
+ this.add_error(errors, field, tests[i], field_val, ifs_match, form);
return errors;
}
}
is_found = 1;
break;
}
- if (! is_found) this.add_error(errors, field, tests[i], field_val, ifs_match);
+ if (! is_found) this.add_error(errors, field, tests[i], field_val, ifs_match, form);
}
/// field equality test
if (value == value2) success = 1;
}
if (not && success || ! not && ! success)
- this.add_error(errors, field, tests[i], field_val, ifs_match);
+ this.add_error(errors, field, tests[i], field_val, ifs_match, form);
}
/// length min check
var tests = this.filter_types('min_len', types);
for (var i = 0; i < tests.length; i ++) {
var n = field_val[tests[i]];
- if (value.length < n) this.add_error(errors, field, tests[i], field_val, ifs_match);
+ if (value.length < n) this.add_error(errors, field, tests[i], field_val, ifs_match, form);
}
/// length max check
var tests = this.filter_types('max_len', types);
for (var i = 0; i < tests.length; i ++) {
var n = field_val[tests[i]];
- if (value.length > n) this.add_error(errors, field, tests[i], field_val, ifs_match);
+ if (value.length > n) this.add_error(errors, field, tests[i], field_val, ifs_match, form);
}
/// now do match types
: ref.split(new RegExp('\\s*\\|\\|\\s*'));
for (var j = 0; j < ref.length; j ++) {
if (typeof(ref[j]) == 'function') {
- if (! value.match(ref[j])) this.add_error(errors, field, tests[i], field_val, ifs_match);
+ if (! value.match(ref[j])) this.add_error(errors, field, tests[i], field_val, ifs_match, form);
} else {
if (! (m = ref[j].match('^\\s*(!\\s*|)m([^\\s\\w])(.*)\\2([eigsmx]*)\\s*$')))
return this.error("Not sure how to parse that match ("+ref[j]+")");
var regexp = new RegExp(pat, opt);
if ( ( not && value.match(regexp))
|| (! not && ! value.match(regexp))) {
- this.add_error(errors, field, tests[i], field_val, ifs_match);
+ this.add_error(errors, field, tests[i], field_val, ifs_match, form);
}
}
}
} else {
return this.error("Not sure how to compare \""+comp+"\"");
}
- if (! hold) this.add_error(errors, field, tests[i], field_val, ifs_match);
+ if (! hold) this.add_error(errors, field, tests[i], field_val, ifs_match, form);
}
}
var tests = this.filter_types('type',types);
for (var i = 0; i < tests.length; i ++)
if (! this.check_type(value, field_val[tests[i]], field, form))
- this.add_error(errors, field, tests[i], field_val, ifs_match);
+ this.add_error(errors, field, tests[i], field_val, ifs_match, form);
/// do custom_js type checks
// this will allow for a custom piece of javascript
var tests = this.filter_types('custom_js',types);
for (var i = 0; i < tests.length; i ++)
if (! eval(field_val[tests[i]]))
- this.add_error(errors, field, tests[i], field_val, ifs_match);
+ this.add_error(errors, field, tests[i], field_val, ifs_match, form);
}
/// all done - time to return
/// the "username" portion of an email address
} else if (type == 'LOCAL_PART') {
if (typeof(value) == 'undefined' || ! value.length) return 0;
- if (! value.match('[^a-z0-9.\\-!&+]')) return 0;
- if (! value.match('^[.\\-]')) return 0;
- if (! value.match('[.\\-&]$')) return 0;
- if (! value.match('(\\.-|-\\.|\\.\\.)')) return 0;
+ if (value.match('[^a-z0-9.\\-!&+]')) return 0;
+ if (value.match('^[.\\-]')) return 0;
+ if (value.match('[.\\-&]$')) return 0;
+ if (value.match('(\\.-|-\\.|\\.\\.)')) return 0;
/// standard IP address
} else if (type == 'IP') {