admin
06-04-2003, 04:28 PM
This function is based on a snippet found at 4GuysFromRolla.com. This function will verify that a user has entered only alphanumeric characters, such as A - Z, a - z, 0 - 9, and the dash and underscore, into a form field. An example of how to call the function is also included.
<%
Function StrCheck(String)
Dim Letter, Flag
Letter = 1
Flag = True
While Letter <= Len(String) And Flag
If ASC(UCase(MID(String, Letter, 1))) < ASC("A") Or
ASC(Ucase(MID(String, Letter, 1))) > ASC("Z") Then
If ASC(MID(String, Letter, 1)) < ASC("0") Or
ASC(MID(String, Letter,1)) > ASC("9") Then
If ASC(MID(String, Letter, 1)) = ASC("-") Or
ASC(MID(String,Letter, 1)) = ASC("_") Then
Flag = True
Else
Flag = False
End If
End If
End If
Letter = Letter + 1
Wend
StrCheck = Flag
End Function
%>
<%
Dim Username
Username = Request.Form("Username")
If StrCheck(Username) Then
'The username is okay, so do your processing or whatever here
Else
'The username is invalid! Do your error stuff here
End If
%>
By FMA
<%
Function StrCheck(String)
Dim Letter, Flag
Letter = 1
Flag = True
While Letter <= Len(String) And Flag
If ASC(UCase(MID(String, Letter, 1))) < ASC("A") Or
ASC(Ucase(MID(String, Letter, 1))) > ASC("Z") Then
If ASC(MID(String, Letter, 1)) < ASC("0") Or
ASC(MID(String, Letter,1)) > ASC("9") Then
If ASC(MID(String, Letter, 1)) = ASC("-") Or
ASC(MID(String,Letter, 1)) = ASC("_") Then
Flag = True
Else
Flag = False
End If
End If
End If
Letter = Letter + 1
Wend
StrCheck = Flag
End Function
%>
<%
Dim Username
Username = Request.Form("Username")
If StrCheck(Username) Then
'The username is okay, so do your processing or whatever here
Else
'The username is invalid! Do your error stuff here
End If
%>
By FMA