Here is my problem, i have a script that checking "personummer".. if "personnummer" is right, it open a alert windows that saying "giltligt personnummer" if its not right its open "ogiltligt personnummer" but now i wanna change that so if personnummer is right, open url domain.com/index.php if personnummer is worng, open domain.com/wrong.php can anyone help me out here <form onsubmit="if(new personnummer(this.pnr.value).valid){ alert('Giltigt personnummer'); } else { alert('0giltigt personnummer'); }; return false;"> Personnummer: <input type="text" name="pnr" size="20" value="xxxxxx-xxxx"> <input type="submit" value="Kontrollera"> </form>
Try this: <form onsubmit="if(new personnummer(this.pnr.value).valid){ window.location.href='right.php'; } else { window.location.href='wrong.php'; }; return false;"> Personnummer: <input type="text" name="pnr" size="20" value="xxxxxx-xxxx"> <input type="submit" value="Kontrollera"> </form>
it seems to work pretty nice... thanks for the help now to another problem i also wanna check so the person is atleasy 18 years old.. If i post the code here, you think you can help me out ?
i know some board crashed when adding javascript, so i remove the start point here is the code, it works good after the changes, now i just want the script to check so they are atleast at legal age of 18... if that is possible type="text/javascript"> function personnummer(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;n<this.alldigits.length;n++){ nn+=((((n+1)%2)+1)*this.alldigits.substring(n,n+1)); } this.checksum=0; for(var n=0;n<nn.length;n++){ this.checksum+=nn.substring(n,n+1)*1; } this.valid=(this.checksum%10==0)?true:false; this.sex=parseInt(this.controldigits.substring(2,3))%2; } </script> <form onsubmit="if(new personnummer(this.pnr.value).valid){ window.location.href='right.php'; } else { window.location.href='wrong.php'; }; return false;"> Personnummer: <input type="text" name="pnr" size="20" value="xxxxxx-xxxx"> <input type="submit" value="Kontrollera"> </form> </body> </html>
its not me that has written the script, but i think it has to do with this.year=RegExp.$1; if the value is 74 its means the person is born 1974 do you use msn or icq ?
I see. In that case your code should look something like this: if (Math.abs(this.nowFullYear-this.fullYear)<18) { alert("You must be at least 18 years old!"); return false; } I do use MSN. Only sometimes during the day though. PM me your time zone and your MSN e-mail.
this person is great, helped me out alot over MSN... thanks again, you was a big help and made me really happy when we got the scritp to work