Código HTML:
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Documento sin título</title> <script> function valida_envia(){ //valido el nombre if (document.registration_form.nombre.value.length==0){ alert("Tiene que escribir su nombre") document.registration_form.nombre.focus() return 0; } } function checkRutField(rut) { var tmpstr = ""; for ( i=0; i < rut.length ; i++ ) if ( rut.charAt(i) != ' ' && rut.charAt(i) != '.' && rut.charAt(i) != '-' ) tmpstr = tmpstr + rut.charAt(i); rut = tmpstr; largo = rut.length; // [VARM+] tmpstr = ""; for ( i=0; rut.charAt(i) == '0' ; i++ ); for (; i < rut.length ; i++ ) tmpstr = tmpstr + rut.charAt(i); rut = tmpstr; largo = rut.length; // [VARM-] if ( largo == 0 ) { alert("Debe ingresar el rut completo."); document.registration_form.rut.focus(); document.registration_form.rut.select(); return false; } for (i=0; i < largo ; i++ ) { if( (rut.charAt(i) != '0') && (rut.charAt(i) != '1') && (rut.charAt(i) !='2') && (rut.charAt(i) != '3') && (rut.charAt(i) != '4') && (rut.charAt(i) !='5') && (rut.charAt(i) != '6') && (rut.charAt(i) != '7') && (rut.charAt(i) != '8') && (rut.charAt(i) != '9') && (rut.charAt(i) !='k') && (rut.charAt(i) != 'K') ) { alert("El valor ingresado no corresponde a un R.U.T valido."); document.registration_form.rut.focus(); document.registration_form.rut.select(); return false; } } var invertido = ""; for ( i=(largo-1),j=0; i>=0; i--,j++ ) invertido = invertido + rut.charAt(i); var drut = ""; drut = drut + invertido.charAt(0); drut = drut + '-'; cnt = 0; for ( i=1,j=2; i<largo; i++,j++ ) { if ( cnt == 3 ) { drut = drut + '.'; j++; drut = drut + invertido.charAt(i); cnt = 1; } else { drut = drut + invertido.charAt(i); cnt++; } } invertido = ""; for ( i=(drut.length-1),j=0; i>=0; i--,j++ ) invertido = invertido + drut.charAt(i); document.registration_form.rut.value = invertido; if(!checkDV(rut)) return false; return true; } function checkDV(crut) { largo = crut.length; if(largo < 2){ alert("Debe ingresar el rut completo."); document.registration_form.rut.select(); document.registration_form.rut.focus(); return false; } if(largo > 2){ rut = crut.substring(0, largo - 1); } else{ rut = crut.charAt(0); } dv = crut.charAt(largo-1); if(!checkCDV(dv)) return false; if(rut == null || dv == null){ return false; } var dvr = '0'; suma = 0; mul = 2; for (i= rut.length -1 ; i >= 0; i--){ suma = suma + rut.charAt(i) * mul; if(mul == 7){ mul = 2; } else{ mul++; } } res = suma % 11; if (res==1){ dvr = 'k'; } else{ if(res==0){ dvr = '0'; } else{ dvi = 11-res; dvr = dvi + ""; } } if(dvr != dv.toLowerCase()){ alert("EL rut es incorrecto."); document.registration_form.rut.select(); document.registration_form.rut.focus(); //document.registration_form.rut.value = ""; return false; } return true; } function checkCDV(dvr) { dv = dvr + ""; if(dv != '0' && dv != '1' && dv != '2' && dv != '3' && dv != '4' && dv != '5' && dv != '6' && dv != '7' && dv != '8' && dv != '9' && dv != 'k' && dv != 'K'){ alert("Debe ingresar un digito verificador valido."); document.registration_form.rut.select(); document.registration_form.rut.focus(); return false; } return true; } function siguiente(){ document.registration_form.paso.value=1; document.registration_form.submit(); } function anterior(){ document.registration_form.paso.value=-1; document.registration_form.submit(); } function Procesa(nPaso) { if (document.registration_form.username.value.length <4 || document.registration_form.username.value.length > 15) { alert('Debes ingresar un nombre de usuario (entre 4 y 15 caracteres)'); document.registration_form.username.focus(); return false; } function dv(T) { var M=0,S=1; for(;T;T=Math.floor(T/10)) S=(S+T%10*(9-M++%6))%11; return S?S-1:'k'; } function esrut(T) { miRut = T.value; nn=miRut.length; if (nn <4) return false; mm=nn-2; gg=String(miRut.charAt(mm)); if (gg != "-") { return false; } digito=String(miRut.charAt(nn-1)); n=1; num=0; j=1; for(i=mm-1;i>=0;i--){ if (String(miRut.charAt(i))=='.'){ if (j%4 !=0) { return false; } } else { num=num + n*parseInt(miRut.charAt(i)); n=n*10; } j=j+1; } digito2=dv(num); if ((digito!=digito2 && digito!='K') || (digito=='K' && digito2!='k')) return false; return true; } if(nPaso==1) siguiente(); else anterior(); } </script> </head> <body> <input name="paso" type="hidden" value="0"> <input name="pasoActual" type="hidden" value="0"> <table> <form action="contactenos.php" method="post" name="registration_form"> <tr><td> Nombres: </td> <td> <input name="nombre" type="text" id="nombre" ><br> </td> </tr> <tr> <td> Rut </td> <td> <input name="rut" id="rut" type="text" maxlength="14" onBlur="if (document.registration_form.rut.value.length>= 0){checkRutField(document.registration_form.rut.value)}else{alert(document.registration_form.rut.value.length)}"> <br> </td> </tr> <tr> <td> E-mail: </td> <td> <input name="email" type="text"><br> </td> </tr> <tr> <td> Telefono: </td> <td> <input name="telefono" type="text"><br> </td> </tr> <tr> <td> Comentarios: </td> <td> <textarea name="comentarios" cols="30" rows="5"> </textarea><br> </td> </tr> <tr> <td> </td> <td> <input name="enviar" type="submit" value="enviar" onclick="valida_envia()"> </form> </td> <tr> </table> </body> </html>
DE ANTEMANO MUCHAS GRACIAS