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

|
|
#1 (permalink) |
![]() |
Validar rut....
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 ![]()
__________________
yerba mala nunca....te la fumes... |
|
|
|
|
|
#3 (permalink) |
![]() |
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)">
__________________
yerba mala nunca....te la fumes... |
|
|
|
|
|
#4 (permalink) |
|
Moderador
![]() ![]() |
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:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Valida_Rut(txtRut.Text) End Sub y las funciones:
Cita:
Si te das cuenta casi todo se queda de la misma manera.. pero sería cosa que lo checaras ok..?? Function StrToCifra(ByVal str As String) As String
Dim str_Aux As String Dim V_Indice1, V_Indice2 As Integer 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 End While V_Indice1 = Len(str_Aux) str = "" While V_Indice1 > 0 str = str & Mid(str_Aux, V_Indice1, 1) V_Indice1 = V_Indice1 - 1 End While Return str End Function Function Remove_Char(ByVal Str As String, ByVal Ch As String) As String Dim str_Aux As String Dim V_Indice1, V_Indice2 As Integer 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 End While Return str_Aux End Function Function Valida_Rut(ByVal Texto As String) Dim RUT_Len As Integer Dim rut As String Dim ACUM Dim Formulario As String = txtRut.Text rut = Remove_Char(UCase(Texto), ".") 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 Dim RUT_DV As String = Mid(rut, RUT_Len, RUT_Len) If RUT_DV = "" Then Label1.Text = "Ingrese RUT con su digito verificador" Valida_Rut = False Exit Function End If Dim pos_guion As Integer = InStr(rut, "-") If pos_guion = 0 Then pos_guion = RUT_Len End If Dim RUT_RUT As String = "000000000000000" & Mid(rut, 1, pos_guion - 1) If (RUT_RUT = "") Then Label1.Text = "Debe Ingresar RUT valido." Valida_Rut = False Exit Function End If If Not IsNumeric(RUT_RUT) Then Label1.Text = "El RUT ingresado posee caracteres no válidos" Valida_Rut = False Exit Function End If Dim RUT_RUT_Len As Integer = Len(RUT_RUT) ACUM = 0 Dim Factor As Integer = 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 End While Dim G As Integer = ACUM Mod 11 Dim h As Integer = 11 - G Dim veri As String Select Case h Case 10 veri = "K" Case 11 veri = "0" Case Else veri = h End Select If Trim(veri) <> Trim(RUT_DV) Then Label1.Text = "El Dígito Verificador ingresado no corresponde al RUT." Valida_Rut = False Exit Function End If txtResultado.Text = Right(StrToCifra(RUT_RUT) & "-" & RUT_DV, 12) Valida_Rut = True End Function Saludos y suerte ![]() |
|
|
|