/*form_pruefen.js * by Thorsten Ruppenstein. v2.1 * 02.03.2005 Fehler bei "nid" und "aid" beseitigt (Überprüfung auf NULL reichte nicht aus) * Erweiterung um Zeitfeld hh:mm * 08.06.2005 Fehler bei parseInt(x) behoben (führende Null); jetzt: parseInt(x, 10) * 27.09.2005 Erweiterung um oid's ("Optionsfelder") * 05.10.2005 Erweiterung um Parameter init_ok, init_fehlertext ("Einbindung" vorgeschalteter Prüfungen); * vgl. Travelprotect.de * 10.10.2005 Erweiterung: Es werden nur Felder geprüft, die auch sichtbar sind. * 28.02.2007 Erweiterung um pid 64 Prüfen auf E-Mail-Adresse * * !!! Spezielle Anpassung (Datum: String "TT.MM.JJJJ" wird als leer interpretiert) * * 17.08.2006 Fehler: bspw. !flag_sid[el_sid], Lösung verwende "1" als init-Wert und "2" als Flag * */ //Rückgabe: TRUE oder FALSE //IE 7/8 polyfill der String.trim Funktion if (!String.prototype.trim) { String.prototype.trim = function () { return this.replace(/^\s+|\s+$/g, ''); }; } function pruefen(form, init_ok, init_fehlertext){ ok = true; fehlertext = "FEHLER BEI DER EINGABE\n\nFolgende Fehler sind aufgetreten:\n"; if (!init_ok) { if (init_fehlertext) { fehlertext += init_fehlertext; ok = false; } } //Felder prüfen /* pid's (kombinierbar, z.Bsp. : 1+2=3) * 1 Feld UNTER KEINEN UMSTÄNDEN LEER * 2 Feld positive ganze Zahl (>=0) * 4 Feld muss Datumsformat TT.MM.JJJJ haben oder leer * 8 checkbox: mindestens eins ausgewählt * 16 select: mindestens eins ausgewählt * 32 Feld muss Uhrzeit sein HH[:|.]MM oder leer * 64 Feld muss E-Mail-Adresse sein w.+[@]w.+[.]w.+ oder leer * 128 Feld muss gültige IBAN sein */ /* aid's * bei gleichem Wert muss mindestens eins grösser 0 sein (verwenden mit pid=2) */ /* oid's * wie aid's, jedoch speziell für Radiobuttons (Optionsfelder) /* sid's * bei gleichem Wert müssen die betreffenden Felder auch den gleichen Inhalt haben */ /* nid's * bei gleichem Wert dürfen nicht alle betreffenden leer sein */ flag_nid = new Array(); flag_message_nid = new Array(); flag_aid = new Array(); flag_message_aid = new Array(); flag_oid = new Array(); flag_message_oid = new Array(); flag_sid = new Array(); flag_value_sid = new Array(); flag_message_sid = new Array(); for (i=0; i0) { if (flag_oid[el_oid]==null || !flag_oid[el_oid]) { flag_oid[el_oid] = 1; flag_message_oid[el_oid] = el_message; } if (getOptionValue(form[el.name])>0) { flag_oid[el_oid] = 2; } } if (el_aid>0) { if (flag_aid[el_aid]==null || !flag_aid[el_aid]) { flag_aid[el_aid] = 1; flag_message_aid[el_aid] = el_message; } if (el.value>0) { flag_aid[el_aid] = 2; } } if (el_sid>0) { if (flag_sid[el_sid]==null || !flag_sid[el_sid]) { flag_sid[el_sid] = 1; flag_message_sid[el_sid] = el_message; flag_value_sid[el_sid] = el.value; } if (el.value!=flag_value_sid[el_sid]) { flag_sid[el_sid] = 2; } } if (el_nid>0) { if (flag_nid[el_nid]==null || !flag_nid[el_nid]) { flag_nid[el_nid] = 1; flag_message_nid[el_nid] = el_message; } if (el.value!=""){ flag_nid[el_nid] = 2; } } if (el_pid & 1) { if (el.value.trim()=="" || el.value == "TT.MM.JJJJ") { ok = false; fehlertext += "- Das Feld " + el_message + " darf nicht leer sein.\n"; } } if (el_pid & 128) { if (IBAN.isValid(el.value)==false && el.value.length>0) { ok = false; fehlertext += "- Das Feld " + el_message + " enthält keine gültige IBAN.\n"; } } if (el_pid & 2) { if(parseInt(el.value, 10)!=el.value || parseInt(el.value, 10)<0) { ok = false; fehlertext += "- Das Feld " + el_message + " darf nur aus Ziffern (0-9) bestehen.\n"; } } if (el_pid & 32) { if (el.value.length>0) { var AusdruckNum = /^(\d{1,2})$/ if (AusdruckNum.test(el.value)==true) { var ErgebnisNum = AusdruckNum.exec(el.value); var stundeNum = parseInt(RegExp.$1, 10); var stunde_okNum = true; if (stundeNum<0 || stundeNum>24) stunde_okNum = false; if (stunde_okNum) { //ersetze 24 durch 00 if (stundeNum==24) { stundeNum=0; } //bringe die Eingabe auf das passende Format (Mit Nullen auffüllen) str_hNum = "" + stundeNum; str_mNum = "0"; if(str_hNum.length<2) str_hNum = "0" + str_hNum; if(str_mNum.length<2) str_mNum = "0" + str_mNum; el.value = str_hNum + ":" + str_mNum; } else { ok = false; fehlertext += "- Das Feld " + el_message + " muss im Format HH:MM sein."; if (!stunde_okNum) fehlertext += "(Fehler bei Stunde)"; fehlertext += "\n"; } } var Ausdruck = /^(\d{1,2})[:|.](\d{1,2})$/ if (Ausdruck.test(el.value)==false) { ok = false; fehlertext += "- Das Feld " + el_message + " muss im Format HH:MM sein.\n"; } else { var Ergebnis = Ausdruck.exec(el.value); var stunde = parseInt(RegExp.$1, 10) var minute = parseInt(RegExp.$2, 10) var stunde_ok = true; var minute_ok = true; if (stunde<0 || stunde>24) stunde_ok = false; if (minute<0 || minute>59) minute_ok = false; if (stunde_ok && minute_ok) { //ersetze 24 durch 00 if (stunde==24) { stunde=0; } //bringe die Eingabe auf das passende Format (Mit Nullen auffüllen) str_h = "" + stunde; str_m = "" + minute; if(str_h.length<2) str_h = "0" + str_h; if(str_m.length<2) str_m = "0" + str_m; el.value = str_h + ":" + str_m; } else { ok = false; fehlertext += "- Das Feld " + el_message + " muss im Format HH:MM sein."; if (!minute_ok && stunde_ok) fehlertext += "(Fehler bei Minute)"; if (!minute_ok && !stunde_ok) fehlertext += "(Fehler bei Stunde und Minute)"; if (minute_ok && !stunde_ok) fehlertext += "(Fehler bei Stunde)"; fehlertext += "\n"; } } } } if (el_pid & 64) { if (el.value.length>0) { /* 04.12.2012: Änderung mn - nach dem @ können mehrere Punkte vorkommen */ //var strReg = "^([a-zA-Z0-9_\.\-])+\@([a-zA-Z0-9\-])+\.([a-zA-Z0-9]{2,4})+$"; var strReg = "^[_a-zA-Z0-9-_]+(\.[_a-zA-Z0-9-_]+)*@[a-zA-Z0-9-_]+(\.[a-zA-Z0-9-_]+)*(\\.[a-zA-Z]{2,4})$"; var regex = new RegExp(strReg); if (regex.test(el.value)==false) { ok = false; fehlertext += "- Das Feld " + el_message + " muss im Format myname@provider.com sein.\n"; } } } if (el_pid & 4) { if (el.value.length>0 && el.value != "TT.MM.JJJJ") { var Ausdruck = /^(\d{1,2})\.(\d{1,2})\.\d{4}$/ if (Ausdruck.test(el.value)==false) { ok = false; fehlertext += "- Das Feld " + el_message + " muss im Format TT.MM.JJJJ sein.\n"; } else { var Ergebnis = Ausdruck.exec(el.value); var tag = parseInt(RegExp.$1, 10); var monat = parseInt(RegExp.$2, 10); switch(monat) { // 31 Tage case 1: case 3: case 5: case 7: case 8: case 10: case 12: if ((tag<1) || (tag>31)) { ok = false; fehlertext += "- Das Feld " + el_message + " muss im Format TT.MM.JJJJ sein. (Tag ung\u00fcltig)\n"; } break; // 30 Tage case 4: case 6: case 9: case 11: if ((tag<1) || (tag>30)) { ok = false; fehlertext += "- Das Feld " + el_message + " muss im Format TT.MM.JJJJ sein. (Tag ung\u00fcltig: " + tag + ")\n"; } break; //Februar maximal 29 case 2: if ((tag<1) || (tag>29)) { ok = false; fehlertext += "- Das Feld " + el_message + " muss im Format TT.MM.JJJJ sein. (Tag ung\u00fcltig)\n"; } break; default: ok = false; fehlertext += "- Das Feld " + el_message + " muss im Format TT.MM.JJJJ sein. (Monat ung\u00fcltig)\n"; break; } } } } if (el_pid & 8) { if (form[el.name].length>0) { zaehler = 0; for (k = 0 ; k < form[el.name].length; k++){ if (form[el.name][k].checked) zaehler = zaehler + 1; } if(zaehler==0) { ok = false; fehlertext += "- Bei " + el_message + " muss mindestens eine Alternative gew\u00e4hlt sein.\n"; } } else { if (!(form[el.name].checked)) { ok = false; fehlertext += "- Das Feld " + el_message + " muss angeklickt sein.\n"; } } } if (el_pid & 16) { if (el.selectedIndex==-1){ ok = false; fehlertext += "- Bei " + el_message + " muss mindestens eine Alternative gew\u00e4hlt sein.\n"; } } } // ist_sichtbar? }//ENDE FOR for (l=0; l bei Grossvater weitermachen default: return ist_sichtbar(el.parentNode); break; } } else { return ist_sichtbar(el.parentNode); } } //keine Eltern mehr else return true; } // ************************************************************************************************************************** //IBAN-Modul von https://www.npmjs.org/package/iban vom 21.02.2013 (function(exports){ // Array.prototype.map polyfill // code from https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/map if (!Array.prototype.map){ Array.prototype.map = function(fun /*, thisArg */){ "use strict"; if (this === void 0 || this === null) throw new TypeError(); var t = Object(this); var len = t.length >>> 0; if (typeof fun !== "function") throw new TypeError(); var res = new Array(len); var thisArg = arguments.length >= 2 ? arguments[1] : void 0; for (var i = 0; i < len; i++) { // NOTE: Absolute correctness would demand Object.defineProperty // be used. But this method is fairly new, and failure is // possible only if Object.prototype or Array.prototype // has a property |i| (very unlikely), so use a less-correct // but more portable alternative. if (i in t) res[i] = fun.call(thisArg, t[i], i, t); } return res; }; } var A = 'A'.charCodeAt(0), Z = 'Z'.charCodeAt(0); /** * Prepare an IBAN for mod 97 computation by moving the first 4 chars to the end and transforming the letters to * numbers (A = 10, B = 11, ..., Z = 35), as specified in ISO13616. * * @param {string} iban the IBAN * @returns {string} the prepared IBAN */ function iso13616Prepare(iban) { iban = iban.toUpperCase(); iban = iban.substr(4) + iban.substr(0,4); return iban.split('').map(function(n){ var code = n.html if (code >= A && code <= Z){ // A = 10, B = 11, ... Z = 35 return code - A + 10; } else { return n; } }).join(''); } /** * Calculates the MOD 97 10 of the passed IBAN as specified in ISO7064. * * @param iban * @returns {number} */ function iso7064Mod97_10(iban) { var remainder = iban, block; while (remainder.length > 2){ block = remainder.slice(0, 9); remainder = parseInt(block, 10) % 97 + remainder.slice(block.length); } return parseInt(remainder, 10) % 97; } /** * Parse the BBAN structure used to configure each IBAN Specification and returns a matching regular expression. * A structure is composed of blocks of 3 characters (one letter and 2 digits). Each block represents * a logical group in the typical representation of the BBAN. For each group, the letter indicates which characters * are allowed in this group and the following 2-digits number tells the length of the group. * * @param {string} structure the structure to parse * @returns {RegExp} */ function parseStructure(structure){ // split in blocks of 3 chars var regex = structure.match(/(.{3})/g).map(function(block){ // parse each structure block (1-char + 2-digits) var format, pattern = block.slice(0, 1), repeats = parseInt(block.slice(1), 10); switch (pattern){ case "A": format = "0-9A-Za-z"; break; case "B": format = "0-9A-Z"; break; case "C": format = "A-Za-z"; break; case "F": format = "0-9"; break; case "L": format = "a-z"; break; case "U": format = "A-Z"; break; case "W": format = "0-9a-z"; break; } return '([' + format + ']{' + repeats + '})'; }); return new RegExp('^' + regex.join('') + '$'); } /** * Create a new Specification for a valid IBAN number. * * @param countryCode the code of the country * @param length the length of the IBAN * @param structure the structure of the undernying BBAN (for validation and formatting) * @param example an example valid IBAN * @constructor */ function Specification(countryCode, length, structure, example){ this.countryCode = countryCode; this.length = length; this.structure = structure; this.example = example; } /** * Lazy-loaded regex (parse the structure and construct the regular expression the first time we need it for validation) */ Specification.prototype._regex = function(){ return this._cachedRegex || (this._cachedRegex = parseStructure(this.structure)) }; /** * Check if the passed iban is valid according to this specification. * * @param {String} iban the iban to validate * @returns {boolean} true if valid, false otherwise */ Specification.prototype.isValid = function(iban){ return this.length == iban.length && this.countryCode === iban.slice(0,2) && this._regex().test(iban.slice(4)) && iso7064Mod97_10(iso13616Prepare(iban)) == 1; }; /** * Convert the passed IBAN to a country-specific BBAN. * * @param iban the IBAN to convert * @param separator the separator to use between BBAN blocks * @returns {string} the BBAN */ Specification.prototype.toBBAN = function(iban, separator) { return this._regex().exec(iban.slice(4)).slice(1).join(separator); }; /** * Convert the passed BBAN to an IBAN for this country specification. * Please note that "generation of the IBAN shall be the exclusive responsibility of the bank/branch servicing the account". * This method implements the preferred algorithm described in http://en.wikipedia.org/wiki/International_Bank_Account_Number#Generating_IBAN_check_digits * * @param bban the BBAN to convert to IBAN * @returns {string} the IBAN */ Specification.prototype.fromBBAN = function(bban) { if (!this.isValidBBAN(bban)){ throw new Error('Invalid BBAN'); } var remainder = iso7064Mod97_10(iso13616Prepare(this.countryCode + '00' + bban)), checkDigit = ('0' + (98 - remainder)).slice(-2); return this.countryCode + checkDigit + bban; }; /** * Check of the passed BBAN is valid. * This function only checks the format of the BBAN (length and matching the letetr/number specs) but does not * verify the check digit. * * @param bban the BBAN to validate * @returns {boolean} true if the passed bban is a valid BBAN according to this specification, false otherwise */ Specification.prototype.isValidBBAN = function(bban) { return this.length - 4 == bban.length && this._regex().test(bban); }; var countries = {}; function addSpecification(IBAN){ countries[IBAN.countryCode] = IBAN; } addSpecification(new Specification("AE", 23, "F03F16", "AE070331234567890123456")); addSpecification(new Specification("AL", 28, "F08A16", "AL47212110090000000235698741")); addSpecification(new Specification("AT", 20, "F05F11", "AT611904300234573201")); addSpecification(new Specification("AZ", 28, "U04A20", "AZ21NABZ00000000137010001944")); addSpecification(new Specification("BA", 20, "F03F03F08F02", "BA391290079401028494")); addSpecification(new Specification("BE", 16, "F03F07F02", "BE68539007547034")); addSpecification(new Specification("BG", 22, "U04F04F02A08", "BG80BNBG96611020345678")); addSpecification(new Specification("BH", 22, "U04A14", "BH67BMAG00001299123456")); addSpecification(new Specification("CH", 21, "F05A12", "CH9300762011623852957")); addSpecification(new Specification("CR", 21, "F03F14", "CR0515202001026284066")); addSpecification(new Specification("CY", 28, "F03F05A16", "CY17002001280000001200527600")); addSpecification(new Specification("CZ", 24, "F04F06F10", "CZ6508000000192000145399")); addSpecification(new Specification("DE", 22, "F08F10", "DE89370400440532013000")); addSpecification(new Specification("DK", 18, "F04F09F01", "DK5000400440116243")); addSpecification(new Specification("DO", 28, "U04F20", "DO28BAGR00000001212453611324")); addSpecification(new Specification("EE", 20, "F02F02F11F01", "EE382200221020145685")); addSpecification(new Specification("ES", 24, "F04F04F01F01F10", "ES9121000418450200051332")); addSpecification(new Specification("FI", 18, "F06F07F01", "FI2112345600000785")); addSpecification(new Specification("FO", 18, "F04F09F01", "FO6264600001631634")); addSpecification(new Specification("FR", 27, "F05F05A11F02", "FR1420041010050500013M02606")); addSpecification(new Specification("GB", 22, "U04F06F08", "GB29NWBK60161331926819")); addSpecification(new Specification("GE", 22, "U02F16", "GE29NB0000000101904917")); addSpecification(new Specification("GI", 23, "U04A15", "GI75NWBK000000007099453")); addSpecification(new Specification("GL", 18, "F04F09F01", "GL8964710001000206")); addSpecification(new Specification("GR", 27, "F03F04A16", "GR1601101250000000012300695")); addSpecification(new Specification("GT", 28, "A04A20", "GT82TRAJ01020000001210029690")); addSpecification(new Specification("HR", 21, "F07F10", "HR1210010051863000160")); addSpecification(new Specification("HU", 28, "F03F04F01F15F01", "HU42117730161111101800000000")); addSpecification(new Specification("IE", 22, "U04F06F08", "IE29AIBK93115212345678")); addSpecification(new Specification("IL", 23, "F03F03F13", "IL620108000000099999999")); addSpecification(new Specification("IS", 26, "F04F02F06F10", "IS140159260076545510730339")); addSpecification(new Specification("IT", 27, "U01F05F05A12", "IT60X0542811101000000123456")); addSpecification(new Specification("KW", 30, "U04A22", "KW81CBKU0000000000001234560101")); addSpecification(new Specification("KZ", 20, "F03A13", "KZ86125KZT5004100100")); addSpecification(new Specification("LB", 28, "F04A20", "LB62099900000001001901229114")); addSpecification(new Specification("LI", 21, "F05A12", "LI21088100002324013AA")); addSpecification(new Specification("LT", 20, "F05F11", "LT121000011101001000")); addSpecification(new Specification("LU", 20, "F03A13", "LU280019400644750000")); addSpecification(new Specification("LV", 21, "U04A13", "LV80BANK0000435195001")); addSpecification(new Specification("MC", 27, "F05F05A11F02", "MC5811222000010123456789030")); addSpecification(new Specification("MD", 24, "U02F18", "MD24AG000225100013104168")); addSpecification(new Specification("ME", 22, "F03F13F02", "ME25505000012345678951")); addSpecification(new Specification("MK", 19, "F03A10F02", "MK07250120000058984")); addSpecification(new Specification("MR", 27, "F05F05F11F02", "MR1300020001010000123456753")); addSpecification(new Specification("MT", 31, "U04F05A18", "MT84MALT011000012345MTLCAST001S")); addSpecification(new Specification("MU", 30, "U04F02F02F12F03U03", "MU17BOMM0101101030300200000MUR")); addSpecification(new Specification("NL", 18, "U04F10", "NL91ABNA0417164300")); addSpecification(new Specification("NO", 15, "F04F06F01", "NO9386011117947")); addSpecification(new Specification("PK", 24, "U04A16", "PK36SCBL0000001123456702")); addSpecification(new Specification("PL", 28, "F08F16", "PL61109010140000071219812874")); addSpecification(new Specification("PS", 29, "U04A21", "PS92PALS000000000400123456702")); addSpecification(new Specification("PT", 25, "F04F04F11F02", "PT50000201231234567890154")); addSpecification(new Specification("RO", 24, "U04A16", "RO49AAAA1B31007593840000")); addSpecification(new Specification("RS", 22, "F03F13F02", "RS35260005601001611379")); addSpecification(new Specification("SA", 24, "F02A18", "SA0380000000608010167519")); addSpecification(new Specification("SE", 24, "F03F16F01", "SE4550000000058398257466")); addSpecification(new Specification("SI", 19, "F05F08F02", "SI56263300012039086")); addSpecification(new Specification("SK", 24, "F04F06F10", "SK3112000000198742637541")); addSpecification(new Specification("SM", 27, "U01F05F05A12", "SM86U0322509800000000270100")); addSpecification(new Specification("TN", 24, "F02F03F13F02", "TN5910006035183598478831")); addSpecification(new Specification("TR", 26, "F05A01A16", "TR330006100519786457841326")); addSpecification(new Specification("VG", 24, "U04F16", "VG96VPVG0000012345678901")); var NON_ALPHANUM = /[^a-zA-Z0-9]/g, EVERY_FOUR_CHARS =/(.{4})(?!$)/g; /** * Utility function to check if a variable is a String. * * @param v * @returns {boolean} true if the passed variable is a String, false otherwise. */ function isString(v){ return (typeof v == 'string' || v instanceof String); } /** * Check if an IBAN is valid. * * @param {String} iban the IBAN to validate. * @returns {boolean} true if the passed IBAN is valid, false otherwise */ exports.isValid = function(iban){ if (!isString(iban)){ return false; } iban = this.electronicFormat(iban); var countryStructure = countries[iban.slice(0,2)]; return !!countryStructure && countryStructure.isValid(iban); }; /** * Convert an IBAN to a BBAN. * * @param iban * @param {String} [separator] the separator to use between the blocks of the BBAN, defaults to ' ' * @returns {string|*} */ exports.toBBAN = function(iban, separator){ if (typeof separator == 'undefined'){ separator = ' '; } iban = this.electronicFormat(iban); var countryStructure = countries[iban.slice(0,2)]; if (!countryStructure) { throw new Error('No country with code ' + iban.slice(0,2)); } return countryStructure.toBBAN(iban, separator); }; /** * Convert the passed BBAN to an IBAN for this country specification. * Please note that "generation of the IBAN shall be the exclusive responsibility of the bank/branch servicing the account". * This method implements the preferred algorithm described in http://en.wikipedia.org/wiki/International_Bank_Account_Number#Generating_IBAN_check_digits * * @param countryCode the country of the BBAN * @param bban the BBAN to convert to IBAN * @returns {string} the IBAN */ exports.fromBBAN = function(countryCode, bban){ var countryStructure = countries[countryCode]; if (!countryStructure) { throw new Error('No country with code ' + countryCode); } return countryStructure.fromBBAN(this.electronicFormat(bban)); }; /** * Check the validity of the passed BBAN. * * @param countryCode the country of the BBAN * @param bban the BBAN to check the validity of */ exports.isValidBBAN = function(countryCode, bban){ if (!isString(bban)){ return false; } var countryStructure = countries[countryCode]; return countryStructure && countryStructure.isValidBBAN(this.electronicFormat(bban)); }; /** * * @param iban * @param separator * @returns {string} */ exports.printFormat = function(iban, separator){ if (typeof separator == 'undefined'){ separator = ' '; } return this.electronicFormat(iban).replace(EVERY_FOUR_CHARS, "$1" + separator); }; /** * * @param iban * @returns {string} */ exports.electronicFormat = function(iban){ return iban.replace(NON_ALPHANUM, '').toUpperCase(); }; /** * An object containing all the known IBAN specifications. */ exports.countries = countries; })(typeof exports == 'undefined' ? this.IBAN = {} : exports);