// validator © Jan Andersen - frontGATE Solutions ApS /* Use input alt or id as "input_id:eval_id" property as input type for regexp Add id to all form elements Use input title property as error focus help text */ var text = /(\w+)/i; var date = /\d{1,2}-\d{1,2}-\d{4,4}/; var rx_search = /(\w+)/i; var subject = /(\w+)/i; var name = /(\w+)\s(\w+)/i; var message = /(\w+)\s(\w+)\s(\w+)/i; var address = /(\w+)/i; var company = /(\w+)/i; var postnr = /^\d{4}/; var city = /(\w+)/i; var phone = /^\d{8}/; var cvr = /^\d{8}/; var ean = /^\d{13}/; var integer = /(\d+)/; var space = /(\s+)/i; var spaces = /^(\s+)$/i; var email_syntax_invalidated = /([\_|\-|\.|\@])([\_|\-|\.|\@])/i; var email_syntax_valid = /^([a-z0-9])([a-z0-9|\_|\-|\.])*([a-z0-9])(\@){1,1}([a-z0-9])([a-z0-9|\_|\-|\.])*([a-z0-9])(\.)([a-z]){2,6}/i; var rx_password = /(\w+)/; var anychar = /(.+)/; var currency_syntax0 = /(\d+)/; var currency_syntax1 = /(\d+)\,\d{2}/; var currency_syntax2 = /[kr](\s)(\d+)\,\d{2}/; var pValue = ''; function pExists(obj, property) { for (var i in obj) { if ('' + i == property) { pValue = '' + obj[i]; return '' + obj[i]; } } pValue = ''; return ''; } function getEval(obj) { evalstr = ""; var objnull = spaces.test(obj.value); if (pExists(obj, "id") != "") { var id_str = new String(obj.id); if (id_str.indexOf(':') > 0) { var xarray = id_str.split(':') var xstr = new String(xarray[1] + ',' + xarray[1]); var earray = xstr.split(','); if (earray[0] != 'null') return earray[0]; if (earray[1] != 'null' && !objnull) return earray[1]; } } if (pExists(obj, "alt") != "") { var xstr = new String(obj.alt + ',' + obj.alt); var earray = xstr.split(","); if (earray[0] != 'null') return earray[0]; if (earray[1] != 'null' && !objnull) return earray[1]; } return ""; } function clsEmail() { this.test=_vmail; } function _vmail(value) { with (this) { if (!email_syntax_valid.test(value)) return false else { if (!email_syntax_invalidated.test(value)) return true; else return false; } } } var email = new clsEmail(); function clsValuta() { this.test=_vvaluta; } function _vvaluta(value) { with (this) { var validated = false; if (currency_syntax0.test(value)) { validated = true; } if (currency_syntax1.test(value)) { validated = true; } if (currency_syntax2.test(value)) { validated = true; } return validated; } } var valuta = new clsValuta(); function clsPassword() { this.test=_vpassword } function _vpassword(value) { with (this) { var tstr = new String(value); if (tstr.length > 5 && tstr.length <= 50) { if (!rx_password.test(value)) return false; else return true; } } return false; } var password = new clsPassword(); function clsSearch() { this.test=_vsearch; } function _vsearch(value) { with (this) { if (!rx_search.test(value)) return false else { var sstr = new String(value); if (sstr.indexOf(" ") > 0) if (sstr.length>3) return true; if (sstr.length>2) return true; else return false; } } } var search = new clsSearch(); function validate_search(id) { if (document.getElementById(id)) { var obj = document.getElementById(id); if (!search.test(obj.value)) { obj.style.borderColor = 'red'; window.alert(obj.title); obj.focus(); return false; } } return true; } // FORM RETRIEVER var allforms = ''; function getFormById(id) { var this_form = new RegExp(id, "i"); var this_index = -1; if (document.forms.length > 0) for (var i = 0; i < document.forms.length; i++) { allforms += "(" + i + '::' + document.forms[i].id + ")"; if (this_form.test(document.forms[i].id)) { try { // IE only // document.forms[i].focus(); if (FormHasFocus(document.forms[i])) this_index = i; } catch (err) { } } } return this_index; } function FormHasFocus(doc) { for (i = 0; i= 0) doc = document.forms[form_index]; else doc = document.forms[form_name]; if (form_obj) doc = form_obj; for (i=0;i