S
SLH
hi people. im trying to validate input received via a text area on an ASP
page before writing it to a database. i cant use client side javascript due
to policy, so it all has to happen on the server. here is what i was trying,
but pieces of it continue to break for one reason or another. the thinking
behind this function was like this:
if the input is less than 10 characters long, fail.
if its 10 characters or greater, but it doesnt appear to contain any words,
fail. (i try this by breaking up the input at space characters into an
array. valid input should have several spaces, indicating several words)
if there are 3 consecutive spaces, fail. (this cant be valid).
then if all that passes, i need to make sure no words are longer than 10
characters. (by looping through the words in the array)
different parts of this fail at different times. for instance if the data
has a newline, it fails (not sure why. is a newline looked at as 3 spaces?)
since there are too many moving parts here i was hoping someone else might
have a better approach to validating the input.
thanks for any help.
Function IsGoodInput(str)
IsGoodInput = True
Dim MyArray, i
MyArray = Split(str, " ")
If Len(str) < 10 Or InStr(str, " ") <> 0 Or UBound(MyArray) = 0 Then
IsGoodInput = False
Else
For i = 0 To UBound(MyArray)
If Len(MyArray(i)) > 10 Then
IsGoodInput = False
Exit For
End If
Next
End If
End Function
page before writing it to a database. i cant use client side javascript due
to policy, so it all has to happen on the server. here is what i was trying,
but pieces of it continue to break for one reason or another. the thinking
behind this function was like this:
if the input is less than 10 characters long, fail.
if its 10 characters or greater, but it doesnt appear to contain any words,
fail. (i try this by breaking up the input at space characters into an
array. valid input should have several spaces, indicating several words)
if there are 3 consecutive spaces, fail. (this cant be valid).
then if all that passes, i need to make sure no words are longer than 10
characters. (by looping through the words in the array)
different parts of this fail at different times. for instance if the data
has a newline, it fails (not sure why. is a newline looked at as 3 spaces?)
since there are too many moving parts here i was hoping someone else might
have a better approach to validating the input.
thanks for any help.
Function IsGoodInput(str)
IsGoodInput = True
Dim MyArray, i
MyArray = Split(str, " ")
If Len(str) < 10 Or InStr(str, " ") <> 0 Or UBound(MyArray) = 0 Then
IsGoodInput = False
Else
For i = 0 To UBound(MyArray)
If Len(MyArray(i)) > 10 Then
IsGoodInput = False
Exit For
End If
Next
End If
End Function