Retroceder   Foros del Web > Programación para sitios web > .NET

Respuesta
 
Herramientas Desplegado
Antiguo 27-oct-2003, 12:54   #1 (permalink)
vamp_02 está en el buen camino
 
Avatar de vamp_02
 
Fecha de Ingreso: noviembre-2002
Ubicación: Santiago de Chile
Mensajes: 367
Enviar un mensaje por Yahoo  a vamp_02
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

__________________
yerba mala nunca....te la fumes...
vamp_02 está desconectado   Responder Citando
Antiguo 27-oct-2003, 13:14   #2 (permalink)
Moderador
RootK llegará a ser famoso muy prontoRootK llegará a ser famoso muy pronto
 
Avatar de RootK
 
Fecha de Ingreso: noviembre-2002
Ubicación: México D.F
Mensajes: 7.552
Enviar un mensaje por MSN a RootK
Claro que te podemos ayudar..pero que quieres validar... una fecha... una cantidad... un rango... etc..

Se quieres detallanos un poco mas...

Saludos
__________________
Nadie roba nada ya que en la vida todo se paga . . .
RootK está desconectado   Responder Citando
Antiguo 27-oct-2003, 14:04   #3 (permalink)
vamp_02 está en el buen camino
 
Avatar de vamp_02
 
Fecha de Ingreso: noviembre-2002
Ubicación: Santiago de Chile
Mensajes: 367
Enviar un mensaje por Yahoo  a vamp_02
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&aacute;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...
vamp_02 está desconectado   Responder Citando
Antiguo 12-nov-2003, 17:06   #4 (permalink)
Moderador
RootK llegará a ser famoso muy prontoRootK llegará a ser famoso muy pronto
 
Avatar de RootK
 
Fecha de Ingreso: noviembre-2002
Ubicación: México D.F
Mensajes: 7.552
Enviar un mensaje por MSN a RootK
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:
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
Si te das cuenta casi todo se queda de la misma manera.. pero sería cosa que lo checaras ok..??

Saludos y suerte
RootK está desconectado   Responder Citando
Respuesta

Calificación: Calificación de Tema: 2 votos, 4,00 de promedio.


Herramientas
Desplegado

Normas de Publicación
No puedes crear nuevos temas
No puedes responder temas
No puedes subir archivos adjuntos
No puedes editar tus mensajes

BB code is Activado
Caritas están Activado
[IMG] está Activado
Código HTML está Desactivado


La Zona horaria es GMT -6. Ahora son las 11:03.


Message Board Statistics

LinkBacks Enabled by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93