![]() |
Validar rut.... Hola a todos......saben necesito un poco de ayuda..... Tengo una pagina y un form, en el cual hay un textbox, que se llama rut.....y necesito validarlo.....algun compatriota, de alma caritativa, tendra el script, para validarlo... Gracias :neurotico |
Claro que te podemos ayudar..pero que quieres validar... una fecha... una cantidad... un rango... etc.. :ojotes: Se quieres detallanos un poco mas... :arriba: Saludos |
Para explicar soy malo...pero este script, me validaba el rut de aca de chile....pero esta en asp, y lo quiero instalar en una pagina asp.net <script language='VBScript'> Dim V_Mensaje Function StrToCifra(ByVal Str) Dim Str_Aux V_Indice1 = Len(Str) V_Indice2 = 0 Str_Aux="" While V_Indice1 > 0 if (V_Indice2 = 3 and V_Indice1 >= 1) Then Str_Aux = Str_Aux & "." V_Indice2 = 0 End If Str_Aux = Str_Aux & Mid(Str,V_Indice1,1) V_Indice1 = V_Indice1 - 1 V_Indice2 = V_Indice2 + 1 WEnd V_Indice1 = Len(Str_Aux) Str="" While V_Indice1 > 0 Str = Str & Mid(Str_Aux,V_Indice1,1) V_Indice1 = V_Indice1 - 1 WEnd StrToCifra = Str End Function Function Remove_Char(Str,Ch) V_Indice1 = Len(Str) V_Indice2 = 1 While V_Indice2 <= V_Indice1 if Ch <> Mid(Str,V_Indice2,1) Then Str_Aux = Str_Aux & Mid(Str,V_Indice2,1) End If V_Indice2 = V_Indice2 + 1 WEnd Remove_Char = Str_Aux End Function Function Valida_Rut(Texto) Dim RUT_Len Dim ACUM set Formulario=document.Form_Acceso RUT = Remove_Char(Ucase(Texto.value),".") RUT = Remove_Char(RUT," ") RUT_Len = Len(RUT) If RUT_Len = 0 Then Msgbox "Debe Ingresar RUT.",48,"Error" Valida_Rut = false Exit Function End If RUT_DV = Mid(RUT, RUT_Len, RUT_Len) if RUT_DV = "" Then Msgbox "Ingrese RUT con su digito verificador",48,"Error" Valida_Rut = false exit Function End If pos_guion = InStr(RUT,"-") if pos_guion=0 Then pos_guion = RUT_Len End If RUT_RUT = "000000000000000" & Mid(RUT, 1, pos_guion-1) if (RUT_RUT="") Then Msgbox "Debe Ingresar RUT valido.",48,"Error" Valida_Rut = false exit Function End If if not IsNumeric(RUT_RUT) then Msgbox "El RUT ingresado posee caracteres no válidos",48,"Error" Valida_Rut = false exit Function end if RUT_RUT_Len = Len(RUT_RUT) ACUM = 0 Factor = 2 While RUT_RUT_Len > 0 if Factor > 7 Then Factor=2 End If ACUM = ACUM + Factor * Mid(RUT_RUT, RUT_RUT_Len,1) RUT_RUT_Len = RUT_RUT_Len-1 Factor = Factor+1 WEnd G = ACUM Mod 11 h = 11 - G Select Case h Case 10 veri = "K" Case 11 veri = "0" Case else veri = h End Select If Trim(veri) <> Trim(RUT_DV) Then Msgbox "El Dígito Verificador ingresado no corresponde al RUT.",48,"Error" Valida_Rut = false Exit Function End If Texto.value = right(StrToCifra(RUT_RUT) & "-" & RUT_DV,12) Valida_Rut = true End Function </script> Y la llamada a la funcion, sería: <input type="text" name=V_Form_Rut size="14" maxlength="13" onchange="Valida_Rut(document.Form_Acceso.V_Form_R ut)"> |
Mira.. siguiendo la lógica que tienes en tu VBscript, para net es casi lo mismo...lo que hice fue tener 1 cuadro de texto (txtRut), un boton y una etiqueta (label1) donde me desplegará cualquier tipo de error. Y el código sería de ésta manera. Cita:
y las funciones: Cita:
Saludos y suerte :arriba: |
Respuesta: Validar rut.... graxias por casualidad llegue aka y me sirvio bastante ya que habia posteado una pregunta parecida |
Respuesta: Validar rut.... <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Página sin título</title> </head> <script type="text/javascript" language=javascript> function revisarDigito( crut, ctexto2 ) { largo = crut.length; rut = crut.substring(0, largo - 1); dv = crut.charAt(largo-1); 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++; } if (suma > 0) { 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.getElementById(ctexto2).value = ""; window.document.getElementById(ctexto2).focus(); return false; } return true; }else { alert("EL rut es incorrecto"); return false; } } function Rut(rut) { var texto; texto = document.getElementById(rut).value; var texto2; texto2 = rut; var tmpstr = ""; for ( i=0; i < texto.length ; i++ ) { if ( texto.charAt(i) != ' ' && texto.charAt(i) != '.' && texto.charAt(i) != '-' ) { tmpstr = tmpstr + texto.charAt(i); } } texto = tmpstr; largo = texto.length; if ( largo > 7 ) { for (i=0; i < largo ; i++ ) { if ( texto.charAt(i) !="0" && texto.charAt(i) != "1" && texto.charAt(i) !="2" && texto.charAt(i) != "3" && texto.charAt(i) != "4" && texto.charAt(i) !="5" && texto.charAt(i) != "6" && texto.charAt(i) != "7" && texto.charAt(i) !="8" && texto.charAt(i) != "9" && texto.charAt(i) !="k" ) { alert("El valor ingresado no corresponde a un R.U.T valido"); document.getElementById(texto2).value = ""; window.document.getElementById(texto2).focus(); return false; } } var invertido = ""; for ( i=(largo-1),j=0; i>=0; i--,j++ ) { invertido = invertido + texto.charAt(i); } var dtexto = ""; dtexto = dtexto + invertido.charAt(0); dtexto = dtexto + '-'; cnt = 0; for ( i=1,j=2; i<largo; i++,j++ ) { if ( cnt == 3 ) { dtexto = dtexto + '.'; j++; dtexto = dtexto + invertido.charAt(i); cnt = 1; } else { dtexto = dtexto + invertido.charAt(i); cnt++; } } invertido = ""; for ( i=(dtexto.length-1),j=0; i>=0; i--,j++ ) { invertido = invertido + dtexto.charAt(i); document.getElementById('textRut').value = invertido.toUpperCase(); } if ( revisarDigito(texto, texto2) ) { alert("El Rut es correcto"); return true; } }else { alert("Debe ingresar el rut completo") window.document.getElementById(texto2).focus(); return false; } return false; } </script> <body> <form id="form1" runat="server"> <div> <asp:TextBox ID="textRut" runat="server"></asp:TextBox> <asp:Button ID="btnValidarRut" runat="server" Text="Validar" /> </div> </form> </body> </html> codebehind VB Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Me.btnValidarRut.Attributes.Add("onclick", "javascript:return Rut('" & textRut.ClientID & "')") End Sub C# protected void Page_Load(object sender, EventArgs e) { btnValidarRut.Attributes.Add("onclick", "javascript:return Rut('" + textRut.ClientID + "')"); } |
Respuesta: Validar rut.... Cita:
hola una consulta como podria hacer esto mismo pero en C# ayuda plis |
Respuesta: Validar rut.... xikristian usa esta pagina http://www.developerfusion.com/tools/convert/vb-to-csharp/ y no revivas temas viejos por favor, crea un nuevo post para aclarar tus dudas. Probablemente te salga un error en algunas lineas pero ya tu debes corregir. Saludos. |
Respuesta: Validar rut.... ok intentare asi graxias |
| La zona horaria es GMT -6. Ahora son las 21:04. |
Desarrollado por vBulletin® Versión 3.8.7
Derechos de Autor ©2000 - 2026, Jelsoft Enterprises Ltd.