02/06/2005, 13:01
|
| | Fecha de Ingreso: marzo-2005
Mensajes: 1.418
Antigüedad: 19 años, 8 meses Puntos: 9 | |
Función de validación genérica de los campos comunes de un formulario:
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
En donde Var sería el campo a validar, len_allowed el máximo permitido de caracteres, numbers_allowed una propiedad boleana que especifica si el campo podrá contener números o no, text_allowed lo mismo que la anterior, pero especificando en true o false si podrá o no contener letras respectivamente.
Un ejemplo de su uso:
Dim FieldName
FieldName = "Mariano"
state = isIt_Valid(FieldName, 12, false, true)
El resultado obviamente sería TRUE.
Saludos y espero que le sirva a alguien.
Suerte!. |