- /// now do match types
- var tests = this.filter_types('match', types);
- for (var i = 0; i < tests.length; i ++) {
- var ref = field_val[tests[i]];
- ref = (typeof(ref) == 'object') ? ref
- : (typeof(ref) == 'function') ? new Array(ref)
- : 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);
- } 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 not = m[1];
- var pat = m[3];
- var opt = m[4];
- if (opt.indexOf('e') != -1)
- return this.error("The e option cannot be used on field "+field+", test "+tests[i]);
- opt = opt.replace(new RegExp('[sg]','g'),'');
- 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);
- }
- }
- }
- }
-
- /// allow for comparison checks
- var tests = this.filter_types('compare', types);
- for (var i = 0; i < tests.length; i ++) {
- var ref = field_val[tests[i]];
- ref = (typeof(ref) == 'object') ? ref : ref.split(new RegExp('\\s*\\|\\|\\s*'));
- for (var j = 0; j < ref.length; j ++) {
- var comp = ref[j];
- if (! comp) continue;
- var hold = false;
- var copy = value;
- if (m = comp.match('^\\s*(>|<|[><!=]=)\\s*([\\d\.\-]+)\\s*$')) {
- if (! copy) copy = 0;
- copy *= 1;
- if (m[1] == '>' ) hold = (copy > m[2])
- else if (m[1] == '<' ) hold = (copy < m[2])
- else if (m[1] == '>=') hold = (copy >= m[2])
- else if (m[1] == '<=') hold = (copy <= m[2])
- else if (m[1] == '!=') hold = (copy != m[2])
- else if (m[1] == '==') hold = (copy == m[2])
- } else if (m = comp.match('^\\s*(eq|ne|gt|ge|lt|le)\\s+(.+?)\\s*$')) {
- m[2] = m[2].replace('^(["\'])(.*)\\1$','$1');
- if (m[1] == 'gt') hold = (copy > m[2])
- else if (m[1] == 'lt') hold = (copy < m[2])
- else if (m[1] == 'ge') hold = (copy >= m[2])
- else if (m[1] == 'le') hold = (copy <= m[2])
- else if (m[1] == 'ne') hold = (copy != m[2])
- else if (m[1] == 'eq') hold = (copy == m[2])
- } else {
- return this.error("Not sure how to compare \""+comp+"\"");
- }
- if (! hold) this.add_error(errors, field, tests[i], field_val, ifs_match);
- }
- }
-
- /// do specific type checks
- 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);
-
- /// do custom_js type checks
- // this will allow for a custom piece of javascript
- // the js is evaluated and should return 1 for success
- // or 0 for failure - the variables field, value, and field_val (the hash) are available
- 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);
+ // the js is evaluated and should return 1 for success
+ // or 0 for failure - the variables field, value, and field_val (the hash) are available
+ if (type.match(/^custom_js\d*$/)) {
+ var value = values.length == 1 ? values[0] : values;
+ if (typeof(_fv) == 'function'
+ ? ! _fv({'value':value, 'field_val':field_val, 'form':form, 'key':field_val.field, 'errors':errors, 'event':v_event})
+ : ! eval(_fv)) v_add_error(errors, field, type, field_val, ifs_match, form);
+ }