portfolio
- programming > vb script / asp
code sample
<%
Dim noChar
Dim StartChar
Dim Chars
Function ValidateField(sFieldValue, sFieldType)
Dim bFieldIsOkay
Dim checker1, checker2
' defaut it to true
bFieldIsOkay = True
' go to the field name to validate the entry
Select Case LCase(sFieldType)
Case "activationid"
If Len(sFieldValue) = 0 Then
bFieldIsOkay = False
Else
If Len(Mid(sFieldValue, 1, 8)) <> 8 Then
bFieldIsOkay = False
Else
If Mid(sFieldValue, 9, 1) <> "-" Then
bFieldIsOkay = False
Else
If Len(Mid(sFieldValue, 10, 17)) <> 8 Then
bFieldIsOkay = False
Else
If hexChecker2() = False Then
bFieldIsOkay = False
Else
If hexChecker2_last8() = False Then
bFieldIsOkay = False
End If
End If
End If
End If
End If
End If
Case "productid"
If Len(sFieldValue) = 0 Then
bFieldIsOkay = False
Else
If Len(Mid(sFieldValue, 1, 6)) <> 6 Then
bFieldIsOkay = False
Else
If Mid(sFieldValue, 7, 1) <> "-" Then
bFieldIsOkay = False
Else
If Len(Mid(sFieldValue, 8, 14)) <> 7 Then
bFieldIsOkay = False
Else
If hexChecker() = False Then
bFieldIsOkay = False
Else
If hexChecker_last7() = False Then
bFieldIsOkay = False
End If
End If
End If
End If
End If
End If
Case "firstname"
If Len(sFieldValue) = 0 Then bFieldIsOkay = False
Case "lastname"
If Len(sFieldValue) = 0 Then bFieldIsOkay = False
Case "company"
If Len(sFieldValue) >= 0 Then bFieldIsOkay = True
Case "streetaddress1"
If Len(sFieldValue) = 0 Then bFieldIsOkay = False
Case "streetaddress2"
If Len(sFieldValue) = 0 OR Len(sFieldValue) > 0 Then bFieldIsOkay =
True
Case "city"
If Len(sFieldValue) = 0 Then bFieldIsOkay = False
Case "state"
If Len(sFieldValue) = 0 Then bFieldIsOkay = False
Case "zip-postal"
If Len(sFieldValue) = 0 Then
bFieldIsOkay = False
Else
If Len(sFieldValue) > 18 Then
bFieldIsOkay = False
End If
End If
Case "country"
If Len(sFieldValue) = 0 Then bFieldIsOkay = False
Case "dayphone"
If Len(sFieldValue) = 0 Then bFieldIsOkay = False
Case "eveningphone"
If Len(sFieldValue) >= 0 Then bFieldIsOkay = True
Case "faxnumber"
If Len(sFieldValue) >= 0 Then bFieldIsOkay = True
Case "email"
If Len(sFieldValue) < 5 Then
bFieldIsOkay = False
Else
If Instr(1, sFieldValue, " ") <> 0 Then
bFieldIsOkay = False
Else
If InStr(1, sFieldValue, "@") < 2 Then
bFieldIsOkay = False
Else
If InStrRev(sFieldValue, ".") < InStr(1, sFieldValue, "@")
+ 2 Then
bFieldIsOkay = False
End If
End If
End If
End If
Case Else 'if an unknown type gets in reject form!
bFieldIsOkay = False
End Select
ValidateField = bFieldIsOkay
End Function
'this checks the first 8 characters of productid to make sure they are
hex only
Function hexChecker()
Dim character
Dim intX
intX = 1
Do While intX < 6
'Find the character
character = Mid(Request.Form("productid"), intX, 1)
If Not (character = "a" Or character = "b" Or character
= "c" _
Or character = "d" Or character = "e" Or character
= "f" _
Or character = "A" Or character = "B" Or character
= "C" _
Or character = "D" Or character = "E" Or character
= "F" _
Or character = "0" Or character = "1" Or character
= "2" _
Or character = "3" Or character = "4" Or character
= "5" _
Or character = "6" Or character = "7" Or character
= "8" _
Or character = "9") Then
hexChecker = False
Exit Function
Else
hexChecker = True
End If
intX = intX+1
Loop
End Function
'this checks the last 8 characters of productid to make sure they are
hex only
Function hexChecker_last7()
Dim character
Dim intX
intX = 8
. . . more
|