Ver Mensaje Individual
  #3 (permalink)  
Antiguo 27/10/2003, 15:04
Avatar de vamp_02
vamp_02
 
Fecha de Ingreso: febrero-2002
Ubicación: Santiago de Chile
Mensajes: 367
Antigüedad: 22 años, 2 meses
Puntos: 0
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...