Ver Mensaje Individual
  #5 (permalink)  
Antiguo 11/07/2005, 07:15
mariano_donati
 
Fecha de Ingreso: marzo-2005
Mensajes: 1.418
Antigüedad: 20 años, 1 mes
Puntos: 9
Yo utilizo esta función propia que hice, también la puse en la librería de clases, no es dificil de entender como funciona.

function isIt_Valid(Var, len_allowed, numbers_allowed, text_allowed)

Dim intruders_symbols
Dim valid_state

intruders_symbols = array("insert","select","drop","database","'","""" ,"*","--","-","delete","update","true","<",">")
Var = Lcase(Var)

valid_state = true

For i=0 To UBound(Intruders_symbols)
If Instr(Var, Intruders_symbols(i)) > 0 then
valid_state = "intruder"
isIt_Valid = valid_state
exit function
end if
next

if numbers_allowed = true And text_allowed = true then
For i = 1 To Len(Var)
If(Mid(Var, i, 1) < "a" Or Mid(Var, i, 1) > "z") And _
(Mid(Var, i, 1) < "0" Or Mid(Var, i, 1) > "9") then
valid_state = false
isIt_Valid = valid_state
exit function
End If
next

elseif numbers_allowed = true And text_allowed = false then
For i = 1 To Len(Var)
If(Mid(Var, i, 1) < "0" Or Mid(Var, i, 1) > "9") then
valid_state = false
isIt_Valid = valid_state
exit function
end if
next

elseif numbers_allowed = false And text_allowed = true then
For i = 1 To Len(Var)
If(Mid(Var, i, 1) < "a" Or Mid(Var, i, 1) > "z") then
valid_state = false
isIt_Valid = valid_state
exit function
end if
Next
end if

if Len(Var) > len_allowed OR Var = "" then
valid_state = false
isIt_Valid = valid_state
exit function
end if

isIt_Valid = valid_state

end function

A esa función fijate que le pasas 4 argumentos. El argumento "Var" es el campo que querés validar. El argumento "len_allowed" es el número máximo de caracteres que puede tener el campo. El tercer argumnento, "numbers_allowed", le tenés que pasar un valor boleano. Si ese campo puede aceptar números, entonces le pasas true, sino le pasas false. Lo mismo pasa con el último argumento, text_allowed.
La función devuelve un boleano si es valido el campo, de acuerdo a lo que le has pasado como argumentos, entonces te devuelve "TRUE", sino te devuelve "FALSE".
Por ejemplo, si llamamos así a la función:

isIt_Valid("Racing",10,false,true)... nos arroja TRUE
isIt_Valid("Racing",10,true,false)... nos arroja FALSE

ESpero que te sirva de algo.
Saludos!.
__________________
Add, never Remove