|
3 Common String Functions
Filename: string_functions.asp
Use: 3 Common string handling function: check
for valid email address, check for alpha-numeric, strip
special characters. Written by Jay McVinney.
<%
'-------------------------------------------------------------------------------------
'-- Check for valid email address
Function IsEmail(sCheckEmail)
Dim sEmail, nAtLoc
IsEmail = True
sEmail = Trim(sCheckEmail)
nAtLoc = InStr(1, sEmail, "@") 'Location
of "@"
If Not (nAtLoc > 1 And (InStrRev(sEmail,
".") > nAtLoc + 1)) Then
&'"@" must exist, and
last "." in string must follow the "@"
&IsEmail = False
ElseIf InStr(nAtLoc + 1, sEmail, "@") >
nAtLoc Then
&'String can't have more
than one "@"
&IsEmail = False
ElseIf Mid(sEmail, nAtLoc + 1, 1) = "."
Then
&'String can't have "."
immediately following "@"
&IsEmail = False
ElseIf InStr(1, Right(sEmail, 2), ".") >
0 Then
&'String must have at
least a two-character top-level domain.
&IsEmail = False
End If
End Function
'-- USAGE
'-- IsEmail("whoeverr@domain") Returns False
'-- IsEmail("who.ever@domain") Returns False
'-- IsEmail("www.askasp.com") Returns False
'-- IsEmail("whoever@domain@net") Returns False
'-- IsEmail("whoever@.domain.net") Returns False
'-- IsEmail("whoever@domain.n") Returns False
'-- IsEmail("whoever@domain.net") Returns True
%>
<%
'-------------------------------------------------------------------------------------
'-- Check for special symbols
Function IsAlphaNumeric(sString)
Dim nChar, i
IsAlphaNumeric = True
For i = 1 To Len(sString)
nChar = Asc(LCase(Mid(sString,
i, 1)))
If not ((nChar > 47 And nChar
< 58) or (nChar > 96 And nChar < 123) or nChar
= 32) Then
IsAlphaNumeric =
False
Exit For
End If
Next
End Function
'-- USAGE:
'-- IsAlphaNumeric("1273 Lovers Lane #B") Returns False
'-- IsAlphaNumeric("1273 B Lovers Lane") Returns True
'-- IsAlphaNumeric("1273 B. Lovers Ln.") Returns False
'-- IsAlphaNumeric("1273 B Lovers Ln") Returns True
%>
<%
'-------------------------------------------------------------------------------------
'-- Strip special symbols
Function StripSymbols(sString)
Dim nCharPos, sOut, nChar
nCharPos = 1
sOut = ""
For nCharPos = 1 To Len(sString)
nChar = Asc(Lcase(Mid(sString,
nCharPos, 1)))
If ((nChar > 47 And nChar
< 58) or (nChar > 96 And nChar < 123) or nChar
= 32) Then
sOut = sOut & Mid(sString,
nCharPos, 1)
End If
Next
StripSymbols = sOut
End Function
'-- USAGE:
'-- StripSymbols("1273 B. Lovers Ln.") 'Returns "1271
B Maiden Ln"
'-- StripSymbols("1273 Lovers Lane #B") 'Returns "1271
Maiden Lane B"
%>
|