// Object type definitions function Field(name, validation, validation_parm, required, required_text) { this.name = name; this.validation = validation; this.validation_parm = validation_parm; this.required = required; this.required_text = required_text; return(this); } function Validation(type, func, en_error, nl_error) { this.type = type; this.func = func; this.en_error = en_error; this.nl_error = nl_error; return(this); } // Validation criteria validateArray=new Array(); validateArray[0] = new Validation("date", "check_date", "is not a valid date. Give three number separated with dashes, for "+ "respectively day,month and year. Note: February has 28 or 29 days!", "is geen geldige datum. Geef drie door streepjes gescheiden getallen voor "+ "dag, maand en jaar. Let op: Februari heeft 28 of 29 dagen!"); validateArray[1] = new Validation("time", "check_time", "is not a valid time. Give three number separated with colons, for "+ "respectively hours ,minutes and seconds. Note: use 24 hour system!", "is geen geldige tijd. Geef drie door puntkomma's gescheiden getallen voor "+ "voor uur, minuten en seconden. Let op: Gebruik 24 uur systeem!"); validateArray[2] = new Validation("datetime", "check_datetime", "is not a valid date/time combination. Give in the format: "+ "DD-MM-YYYY hh:mm:ss, for respectively Day, Month, Year, Hours, Minutes and Seconds.", "is geen geldige datum/tijd combinatie. Gebruik het formaat: "+ "DD-MM-JJJJ uu:mm:ss, voor respectievelijk Dag, Maand, Jaar, uur, minuten en seconden."); validateArray[3] = new Validation("email", "check_email", "is not a valid Email address!", "is geen geldig e-mail adres!"); validateArray[4] = new Validation("url", "check_url", "is not a valid URL. An URL must start with http://!", "is geen geldige URL! Een URL moet beginnen met http://"); validateArray[5] = new Validation("zipcode", "check_zipcode", "is not Zipcode. A Zipcode is 4 numbers, a space and then 2 letters!", "is geen geldige postcode. Een postcode heeft vier cijfers, dan een spatie gevolgd door 2 letters!"); validateArray[6] = new Validation("numeric", "check_numeric", "is not a valid numeric. Only give numbers!", "is geen geldige nummer. Er kunnen alleen cijfers worden ingevoerd!"); validateArray[7] = new Validation("alpha", "check_alpha", "is not a valid word. Only give letters!", "is geen geldig woord. Er kunnen alleen letters worden ingevoerd!"); validateArray[8] = new Validation("alphanum", "check_alphanum", "is not a valid word, only give numbers and letters!", "is geen geldige woord. Geef uitsluitend letters en cijfers!"); validateArray[9] = new Validation("domain_name", "check_domain_name", "is not a valid domain_name! Only give letters, numbers and dashes", "is geen geldige domain_name! Geef alleen letters, cijfers en liggende streepjes."); validateArray[10]= new Validation("percentage", "check_percentage", "is not a valid percentage. Give a value between 0% and 100%!", "is geen geldige percentage. Dit moet tussen de 0% en 100% liggen!"); validateArray[11]= new Validation("double", "check_double", "is not a valid double. Only one dot or comma is allowed!", "is geen geldige waarde. Slechts een punt of komma toegestaan!"); validateArray[12]= new Validation("telnum", "check_telnum", "is not a valid telephone number. Give net nr. and local nr., separated with a dash", "is geen geldig telefoon nummer. Geef netnr. en abonneenr., gescheiden door een liggend streepje!"); validateArray[13]= new Validation("hex_color", "check_hex_color", "give RGB color hexcode (e.g. #12FFDD)", "geef een RGB kleur hexcode (bv. #12FFDD)"); validateArray[14]= new Validation("credit_card", "check_valid_credit_card", "is not a valid credit card nummer!", "is geen geldig credit kaart nummer!"); validateArray[15]= new Validation("bank_giro", "check_bank_giro", "is not a valid (Dutch) Giro- or Bank number!", "is geen geldig Nederlands Giro- of Bankrekeningnummer!"); function check_form_fields(form) { var form_ok=true; var i; // If there is a rich text editor, make sure it updates it's fields! if(typeof(tinyMCE) != "undefined" && typeof(tinyMCE.triggerSave) == "function" ) { tinyMCE.triggerSave(); } // If user wants to perform an action, don't check fields! if(form._action.value != "" && form._action.value != "update") return form_ok; // if(form._action.value == "roundtrip") // Roundtrip, don't check fields! // return form_ok; // See if a private_check_form() is provided, and use it if found... if (window.private_check_form && window.private_check_form(form)==false) return false; for(j=0; j 0) { re = /^(\d+)$/; if(fieldArray[j].required.match(re)) expression = fieldArray[j].required; else { re = /(\w+)/gi; expression = fieldArray[j].required.replace(re,"(form[\"$1\"].value.length>0)"); } required = eval(expression); if(required) { if(type == 'radio') { if(form[ctrl_name].length > 0) { var is_checked = false; for( var i=0; i < form[ctrl_name].length; i++) { if(form[ctrl_name][i].checked) is_checked = true; } if(!is_checked) form_ok = false; } } else { if(form[ctrl_name].options && typeof(form[ctrl_name].selectedIndex) == 'number') value = form[ctrl_name].options[form[ctrl_name].selectedIndex].value; else value = form[ctrl_name].value; if(value.length <= 0) form_ok = false; } } if(!form_ok) { if(fieldArray[j].required_text && fieldArray[j].required_text.length > 0) { if(typeof(activate_parent_tab) == 'function') activate_parent_tab(form[ctrl_name]); if(form[ctrl_name].focus) form[ctrl_name].focus(); else if(form[ctrl_name][0].focus) form[ctrl_name][0].focus(); alert(fieldArray[j].required_text); } break; } } if(form_ok) { for(k=0; k= validateArray.length || fieldArray[j].validation != validateArray[k].type) continue; check = "form_ok=" + validateArray[k].func + "(form[ctrl_name],fieldArray[j].validation_parm);" eval(check); if(!form_ok) { if(typeof(activate_parent_tab) == 'function') activate_parent_tab(form[ctrl_name]); form[ctrl_name].focus(); alert('"' + form[ctrl_name].value + '"' + " " + eval("validateArray[k]."+lang+"_error")); break; } } } if (form_ok) { mark_submitted(); } return(form_ok); } function check_email(field, validation_parm) { // If the e-mail address contains: // the e-mail address contains an invalid syntax. Or, if the // syntax does not match the following regular expression pattern // it fails basic syntax verification. // Basic syntax requires: one or more characters before the @ sign, // followed by an optional '[', then any number of letters, numbers, // dashes or periods (valid domain/IP characters) ending in a period // and then 2, 3 or 4 letters (for domain suffixes) or 1 to 3 numbers // (for IP addresses). An ending bracket is also allowed as it is // valid syntax to have an email address like: user@[255.255.255.0] // AvD on nov 14th 2005 - .info was not accepted because it was 4 chars long: regexp corrected... var text=field.value; if (!text.length) return(true); re1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; re2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/; if (re1.test(text) || !re2.test(text)) { return(false); } return(true); } function check_url(field, validation_parm) { var text=field.value; if (!text.length) return(true); re = /https?:\/\//i; if (!re.test(text)) { return(false); } return(true); } function check_numeric(field, validation_parm) { var i; var text=field.value; if (!text.length) return(true); if(!text.match(/^[0-9]*$/)) { return false; } return true; } function check_alpha(field, validation_parm) { var i; var text=field.value; if (!text.length) return(true); if(!text.match(/^[A-Za-z]*$/)) { return false; } return true; } function check_alphanum(field, validation_parm) { var i; var text=field.value; if (!text.length) return(true); if(!text.match(/^[0-9A-Za-z]*$/)) { return false; } return true; } function check_zipcode(field, validation_parm) { var text=field.value; if (!text.length) return(true); if(!text.match(/^[0-9A-Za-z ]*$/)) return false; text = text.toUpperCase(); // If it is a Dutch postal code without space, put a space in. if(text.match(/^[0-9]{4}[A-Z]{2}$/)) text = text.substring(0,4)+' '+text.substring(4,6); field.value = text; return true; } function check_domain_name(field, validation_parm) { // check_s the name is a valid secondlevel domainname (don't include TLD!)... var i; var text=field.value; if (!text.length) return(true); if (!text.match(/^[\-A-Za-z0-9]*$/)) { return false; } return true; } function check_percentage(field, validation_parm) { var text=field.value; if (!text.length) return(true); if(!text.match(/^[0-9]*$/)) { return false; } if (parseInt(text,10) < 0 || parseInt(text,10) > 100) { return false; } return true; } function check_double(field, validation_parm) { // First do some formatting, any comma's are replaced by points... var text=field.value; if (!text.length) return(true); var text = text.replace(/\,/gi,'.'); // AvD on oct 25th 2005: Also allow negative doubles needed for accounting etc... if(!text.match(/^[\-\.0-9]*$/)) { return false; } parts = text.split('.'); if (parts.length > 2) { return false; } return true; } function check_telnum(field, validation_parm) { var text=field.value; if(!text.match(/^[0-9 +()\-]*$/)) return false; // Replace multiple spaces by 1 text = text.replace(/\ +/gi,' '); field.value = text; return true; } function check_hex_color(field, validation_parm) { var text=field.value; if (!text.length) return(true); text = text.toUpperCase(); if(!text.match(/^#/)) text = '#' + text; if(!text.match(/^#[0-9A-F]{6}$/)) { return(false); } field.value = text; return (true); } function check_credit_card(field, validation_parm) { var text=field.value; var i; if (!text.length) return(true); if (text.length > 19) return (false); Sum = 0; Mul = 1; Len = text.length; for (i = 0; i < Len; i++) { Digit = text.substring(Len-i-1,Len-i); Tproduct = parseInt(Digit ,10)*Mul; if (Tproduct >= 10) Sum += (Tproduct % 10) + 1; else Sum += Tproduct; if (Mul == 1) Mul++; else Mul = Mul - 1; } if ((Sum % 10) == 0) return (true); return (false); } function check_visa(field, validation_parm) { var text=field.value; if (!text.length) return(true); if (((text.length == 16) || (text.length == 13)) && (text.substring(0,1) == 4)) return check_credit_card(field); return false; } function check_master_card(field, validation_parm) { var text=field.value; if (!text.length) return(true); FirstDig = text.substring(0,1); SecondDig = text.substring(1,2); if ((text.length == 16) && (FirstDig == 5) && ((SecondDig >= 1) && (SecondDig <= 5))) return check_credit_card(field); return false; } function check_american_express(field, validation_parm) { var text=field.value; if (!text.length) return(true); FirstDig = text.substring(0,1); SecondDig = text.substring(1,2); if ((text.length == 15) && (FirstDig == 3) && ((SecondDig == 4) || (SecondDig == 7))) return check_credit_card(field); return false; } function check_valid_credit_card(field, validation_parm) { var text=field.value; if (!text.length) return(true); text = text.replace(/[^0-9]/gi,'-'); text = text.replace(/\-+/gi,'-'); text = text.replace(/^\-/gi,''); if (!check_credit_card(field, validation_parm)) return false; if (!check_master_card(field, validation_parm) && !check_visa(field, validation_parm) && !check_american_express(field, validation_parm)) return false; return true; } function check_bank_giro(field, validation_parm) { // Check if number is a valid 7 digit 'Postbank' giro number (optionally prefixed with 'P'), // or more general 13 digit bank-number. Adds 'P' to 7 digit numbers. var text = field.value; if (!text.length) return(true); text = text.replace(/[^0-9]/gi,''); // Keep only the numbers... if (text.length==7) { // Postbank... field.value = 'P'+text; return(true); } // Do the 11-test... if (text.length!=9) return(false); Sum=0; Factor=9; for (i=0; i<9; i++) { Digit = parseInt(text.substring(i,i+1)); Sum += parseInt(Factor*Digit); Factor = Factor-1; } if ((Sum%11)==0) return(true); return(false); } function is_month(s) { i = parseInt(s,10); return (s.match(/^[0-9]*$/) && i >= 1 && i <= 12); } function is_year(s) { i = s.length; return (s.match(/^[0-9]*$/) && ((i == 2) || (i == 4))); } function is_day(s) { i = parseInt(s,10); return (s.match(/^[0-9]*$/) && i >= 1 && i <= 31); } function days_in_february(year) { return (((year % 4 == 0) && ((!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28); } function is_date(text) { var DaysInMonth = new Array('31','29','31','30','31','30','31','31','30','31','30','31'); // catch invalid years (not 2- or 4-digit) and invalid months and days. var parts = text.split('-'); // Check if three parts where given (5-9-2001)... if (parts.length != 3) return false; day = parts[0]; month = parts[1]; year = parts[2]; if (! (is_year(year) && is_month(month) && is_day(day))) return false; // Explicitly change type to integer to make code work in both // JavaScript 1.1 and JavaScript 1.2. var year = parseInt(year,10); var month = parseInt(month,10); var day = parseInt(day,10); // catch invalid days, except for February if (day > DaysInMonth[month-1]) return false; if ((month == 2) && (day > days_in_february(year))) return false; return true; } function check_date(field) { var text=field.value; if(!text.length) return(true); // Be more tolerant (11-4-2001)... text = text.replace(/\/+/gi,'-'); text = text.replace(/\ +/gi,'-'); if(!is_date(text)) return false; var parts = text.split('-'); day = parseInt(parts[0],10); month = parseInt(parts[1],10); year = parseInt(parts[2],10); if (day < 10) day = '0' + day; if (month < 10) month = '0' + month; if (year < 100) if (year > 40) year = year +1900; else year = year +2000; if (year < 1000) year = year +1900; field.value = day + '-' + month + '-' + year; return true; } function check_time(field) { var text=field.value; if(!text.length) return(true); if(!text.match(/^\d\d:\d\d:\d\d$/)) return(false); if(!is_time(text)) return(false); return true; } function is_time(text) { var parts = text.split(':'); hour = parts[0]; min = parts[1]; sec = parts[2]; if(hour >= 24 || hour < 0) return false; if(min >= 60 || min < 0) return false; if(sec >= 60 || sec < 0) return false; return true; } function check_datetime(field) { var text=field.value; if(!text.length) return(true); var parts = text.split(' '); date = parts[0]; time = parts[1]; if(!is_date(date) || !is_time(time)) return false; var parts = date.split('-'); day = parseInt(parts[0],10); month = parseInt(parts[1],10); year = parseInt(parts[2],10); var parts = time.split(':'); hour = parseInt(parts[0],10); min = parseInt(parts[1],10); sec = parseInt(parts[2],10); if (day < 10) day = '0' + day; if (month < 10) month = '0' + month; if (year < 100) if (year > 40) year = year +1900; else year = year +2000; if (year < 1000) year = year +1900; if (hour < 10) hour = '0' + hour; if (min < 10) min = '0' + min; if (sec < 10) sec = '0' + sec; field.value = day + '-' + month + '-' + year + ' ' + hour + ':' + min + ':' + sec; return true; }