var validator = new function () { /*Output functions*/ this.isValid = new function () { this.socialSecNo = function (countryCode, socialSecNo) { switch (countryCode.toUpperCase()) { case 'FIN': case 'FI': return validator.isValidFinSocialSecNo(socialSecNo); break; case 'SWE': case 'SE': if (socialSecNo.length == 10) { //Lisätään (-) merkki, koska tarkastaja vaatii sen socialSecNo = socialSecNo.substr(0, 6) + '-' + socialSecNo.substr(6, 10); } return validator.isValidSweSocialSecNo(socialSecNo); break; default : return true; break; } }; this.date = function (str) { var tmp = str.split('-'); var day = tmp[2]; var month = tmp[1]; var year = tmp[0]; if ((month=='04' || month=='06' || month=='09' || month==11) && day==31) { return false; } if (month == '02') { // check for february 29th var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); if (parseInt(day)>29 || (parseInt(day)==29 && !isleap)) { return false; } } var date = new Date(year, month, day); return !(isNaN(date)); }; this.IBAN = function (fieldName) { // xjaxissa tehdään tarkastus ja asetetaan cookie 1:ksi, jos on tilinumero on // IBAN if (GetCookie(fieldName + '_is_IBAN') == '1') { return true; } return false; }; this.AccountNumber = function (countryCode, AccountNum) { switch (countryCode.toUpperCase()) { case 'FI': case 'FIN': return validator.isValidFinAccountNum(AccountNum); break; case 'SE': case 'SWE': return validator.isValidSweAccountNum(AccountNum); break; default : return true; break; } }; }; /*Inside functions*/ this.isValidFinSocialFormat = function(str){ if ((str.length != 10) && (str.length != 11) || (str.substring(6,7) != '-') && (str.substring(6,7) != '+') && (str.substring(6,7) != 'A')){ return false; } return true; }; this.isValidFinSocialSecNo = function(num){ if (this.isValidFinSocialFormat(num)){ var variable = num.substring(0,6) + num.substring(7,10); var lastLetter = num.substring(10,11); var row = "0123456789ABCDEFHJKLMNPRSTUVWXY"; var checkLetter = row.substring(variable % 31, variable % 31 +1); if (lastLetter == '') { return false; }else { if (lastLetter == checkLetter) return true; else return false; } } return false; }; this.isValidSweSocialSecNo = function (num) { if(new SwePersonNummer(num).valid){ return true; }else{ return false; } }; this.isValidSweAccountNum = function (Accountnum) { var ref; var ref_chr; var clearing; /* * * Accountnum = StripSpacesStr(Accountnum); Accountnum = DelChars(Accountnum, * '-'); Accountnum = trim(Accountnum); */ while ( Accountnum.indexOf(" ") > 0 ) { Accountnum = Accountnum.replace(/ /,""); } while ( Accountnum.indexOf("-") > 0 ) { Accountnum = Accountnum.replace(/-/,""); } if ( Accountnum != '' ) { Clearing = Accountnum.substr(0, 4); ref_chr = Accountnum.charAt(Accountnum.length-1); if ( ((Clearing >= '9090') && (Clearing <= '9099')) || ((Clearing >= '9040') && (Clearing <= '9049')) || ((Clearing >= '9190') && (Clearing <= '9199')) || ((Clearing >= '2300') && (Clearing <= '2399')) || ((Clearing >= '9020') && (Clearing <= '9029')) || ((Clearing >= '4000') && (Clearing <= '4999') && (Accountnum.length != 14)) || ((Clearing >= '9150') && (Clearing <= '9196')) || ((Clearing >= '9200') && (Clearing <= '9209')) || ((Clearing >= '9100') && (Clearing <= '9109'))|| ((Clearing >= '9550') && (Clearing <= '9569')) ) { ref = Accountnum.substr(0,Accountnum.length-1); // Ref := copy(Accountnum, 1, Length(Accountnum)); return (mod11_chknum(ref) == ref_chr); } else { if ( ((Clearing >= '1200') && (Clearing <= '1399')) || ((Clearing >= '9260') && (Clearing <= '9269')) || ((Clearing >= '7000') && (Clearing <= '7999')) || ((Clearing >= '9270') && (Clearing <= '9279')) || ((Clearing >= '9170') && (Clearing <= '9179')) || ((Clearing >= '3400') && (Clearing <= '3409')) || ((Clearing >= '9060') && (Clearing <= '9069')) || ((Clearing >= '1100') && (Clearing <= '1199') && (Accountnum.length != 14)) || ((Clearing >= '1400') && (Clearing <= '2099') && (Accountnum.length != 14)) || ((Clearing >= '3000') && (Clearing <= '3399') && (Accountnum.length != 14)) || ((Clearing >= '3410') && (Clearing <= '3999') && (Accountnum.length != 14)) || ((Clearing >= '9230') && (Clearing <= '9239')) || ((Clearing >= '5000') && (Clearing <= '5999')) || ((Clearing >= '9400') && (Clearing <= '9449')) || ((Clearing >= '9460') && (Clearing <= '9469')) || ((Clearing >= '9280') && (Clearing <= '9289')) || ((Clearing >= '9250') && (Clearing <= '9259')) || ((Clearing >= '9120') && (Clearing <= '9124')) || ((Clearing >= '9130') && (Clearing <= '9149')) || ((Clearing >= '9050') && (Clearing <= '9059')) ) { ref = Accountnum.substr(1, Accountnum.length-2); return (mod11_chknum(ref) == ref_chr); /* * ref := copy(Accountnum, 2, Length(Accountnum) - 1); if (mod11_chknum(ref) = * ref_chr) Then Result := True; */ } else if ( ((Clearing >= '3300') && (Clearing <= '3300') && (Accountnum.length == 14)) || ((Clearing >= '4000') && (Clearing <= '4999') && (Accountnum.length == 14)) || ((Clearing >= '1100') && (Clearing <= '1199') && (Accountnum.length == 14)) || ((Clearing >= '1400') && (Clearing <= '2099') && (Accountnum.length == 14)) || ((Clearing >= '3000') && (Clearing <= '3399') && (Accountnum.length == 14)) || ((Clearing >= '3410') && (Clearing <= '3999') && (Accountnum.length == 14)) ) { ref = Accountnum.substr(Accountnum.length-10, 9); return (mod10_chknum(ref) == ref_chr); /* * ref := copy(Accountnum, Accountnum.length - 9, 10); if (mod10_chknum(ref) = * ref_chr) The Result := True; */ } else if ( ((Clearing >= '6000') && (Clearing <= '6999')) ) { ref = Accountnum.substr(Accountnum.length-9, 8); return (mod11_chknum(ref) == ref_chr); /* * ref := copy(Accountnum, Length(Accountnum) - 8, 9); if (mod11_chknum(ref) = * ref_chr) Then Result := True; */ } else if ( ((Clearing >= '9500') && (Clearing <= '9549')) || ((Clearing >= '9960') && (Clearing <= '9969')) ) { ref = Accountnum.substr(4, Accountnum.length-5); return (mod10_chknum(ref) == ref_chr); /* * ref := copy(Accountnum, 5, Length(Accountnum) - 4); if * (swe_mod10_chknum(ref) = ref_chr) Then Result := True; */ } else if ( ((Clearing >= '8000') && (Clearing <= '8999'))) { ref = Accountnum.substr(4, Accountnum.length-5); return (mod10_chknum(ref) == ref_chr); /* * ref := copy(Accountnum, 5, Length(Accountnum) - 4); if * (swe_mod10_chknum(ref) = ref_chr) Then Result := True; */ } else if ( ((Clearing >= '9180') && (Clearing <= '9189')) || ((Clearing >= '9300') && (Clearing <= '9329')) || ((Clearing >= '9330') && (Clearing <= '9349')) || ((Clearing >= '9570') && (Clearing <= '9579')) ) { ref = Accountnum.substr(4, Accountnum.length-5); return (mod10_chknum(ref) == ref_chr); /* * ref := copy(Accountnum, 5, Length(Accountnum) - 4); if * (swe_mod10_chknum(ref) = ref_chr) Then Result := True; */ } } } return ( false ); }; this.isValidFinAccountNum = function (ref) { var ref_chr; if (ref != '') { ref_chr = ref.charAt(ref.length-1); ref = Set14chr(ref); // Ei saa olla yli 14 merkkiä if (ref.length > 14) { return false; } if (mod10_chknum(ref) == ref_chr) return true; } return false; }; }; function SwePersonNummer(nr){ this.valid=false; if(!nr.match(/^(\d{2})(\d{2})(\d{2})\-(\d{4})$/)){ return false; } this.now=new Date(); this.nowFullYear=this.now.getFullYear()+""; this.nowCentury=this.nowFullYear.substring(0,2); this.nowShortYear=this.nowFullYear.substring(2,4); this.year=RegExp.$1; this.month=RegExp.$2; this.day=RegExp.$3; this.controldigits=RegExp.$4; this.fullYear=(this.year*1<=this.nowShortYear*1)?(this.nowCentury+this.year)*1:((this.nowCentury*1-1)+this.year)*1; var months = new Array(31,28,31,30,31,30,31,31,30,31,30,31); if(this.fullYear%400==0||this.fullYear%4==0&&this.fullYear%100!=0){ months[1]=29; } if(this.month*1<1||this.month*1>12||this.day*1<1||this.day*1>months[this.month*1-1]){ return false; } this.alldigits=this.year+this.month+this.day+this.controldigits; var nn=""; for(var n=0;n0; cnt--){ digit = weight * (str.charAt(cnt-1)); /* add tens digit to ones digit to the sum */ sum = sum + Math.floor(digit / 10) + (digit % 10); weight=weight==2?1:2; } /* subtract ones digit of the sum from 10 return ones digit of result */ var mod = (10-sum%10)%10; return mod; } function Set14chr(s){ var part1, part2, part3, InsertPos, substr, i; if (s != '') { s = StripSignStr(s); InsertPos = 6; if ((s.substr(0,1) == '4') || (s.substr(0,1) == '5') ) InsertPos = 7; subStr = ''; for (i = s.length; i < 14; i++) { subStr += '0'; } part1 = s.substr(0, InsertPos); part2 = s.substr(InsertPos, s.length-1); return part1+ subStr +part2; } } function StripSignStr(s) { var nosign, i; if (s != '') { nosign = ''; for (i = 0; i < s.length; i++) { if (s.substr(i,1) != '-') { nosign = nosign + s.charAt(i) ; } } return nosign; } return ''; } function mod11_chknum( Ref ) { var Ref_nospace; var Ref_sum; var Ref_chk; var Mod_mult; var i; Ref_nospace = StripSpacesStr(Ref); if ( Ref_nospace != '') { Ref_sum = 0; Mod_mult = 1; for ( i = Ref_nospace.length-1; i >= 0 ; i--) { Mod_mult++; Mod_mult = (Mod_mult%11); if ( Mod_mult == 0) Mod_mult = 1; Ref_sum = Ref_sum + Ref_nospace[i]* Mod_mult; } Ref_chk = Ref_sum % 11; if ( Ref_chk > 1 ) Ref_chk = 11 - Ref_chk; else Ref_chk = 0; return ( Ref_chk ); } return (''); } function StripSpacesStr(str) { while ( str.indexOf(" ") > 0 ) { str = str.replace(/ /,""); } return ( str ); }