Couldn't find a total ISBN validation script out there, heres one if anyone needs it.
Validates all parts of the ISBN code as it currently stands. This includes:
- Allowed inputs
- Input lengths
- Check digits
- Group identifiers
- Publisher identifiers
Probably could of done the group/publisher identifiers better using
arrays and loops to stop the repeated code, but meh, can't be
bothered. I think in my case I overkilled the task at hand anyway.
Can easily be adapted for ASP, just remove the msgbox lines at the
bottom of the code. Stick it in a function if you want as
well. Whatever!
[code]
'********
'ISBN VALIDATION
'(c) Thomas Gullen 2004
'********
'Notes
'Currently checks if:
' ISBN contains digits only
' ISBN is 10 digits long
' Validates check digit
' Validates group identifier
' Validates publisher identifier
'Allows for:
' X as check digit
' Inter digit formatting
'
'All in accordance with ISBN standards (isbn.org)
'Declare new variables
Dim strEnteredISBNNumber As String 'ISBN number entered by user
Dim strTakenChar As String 'Holds a single character
Dim strDetailedErrorMsg As String 'Holds the detailed error message returned
Dim intLengthOfISBN As Integer 'Length of the ISBN number
Dim intLooper As Integer   ; ; ; 'Loop counter
Dim blnValidISBN As Boolean 'Is ISBN valid
Dim intCheckDigRunTot As Integer 'Holds the check digit formula running total
Dim intDigitValue As Integer 'Holds digit value
Dim intCheckDigitVal As Integer 'The check digit
Dim intCheckModulusRes As Integer 'Holds check digit modulus 11 remainder
Dim intGroupIdentifier As Long 'Validates group identifier
Dim blnFoundValGI As Boolean 'Holds if a valid group identifier has been identified
Dim intGILen As
Integer   ; ; ;
'Length of found group identifier
Dim strPubIdentifier As String 'Holds publisher identifier
Dim blnFoundValPub As Boolean 'Has a valid publisher been found
Dim intPubIdentifier As Long 'Holds sliced publisher value
'Initialise variables
intLooper = 0
intDigitValue = 10
intCheckDigRunTot = 0
strDetailedErrorMsg = ""
blnValidISBN = True
blnFoundValGI = False
blnFoundValPub = False
'Take value entered in form
Text0.SetFocus
strEnteredISBNNumber = Text0.Text
'Uppercase it to resolve formatting issues
strEnteredISBNNumber = UCase(strEnteredISBNNumber)
'Remove any inter digit formatting that may occur
strEnteredISBNNumber = Replace(strEnteredISBNNumber, " ", "")
strEnteredISBNNumber = Replace(strEnteredISBNNumber, "-", "")
strEnteredISBNNumber = Replace(strEnteredISBNNumber, "ISBN", "")
'Take length of entered ISBN number
intLengthOfISBN = Len(strEnteredISBNNumber)
'Make sure ISBN contains 10 digits
If intLengthOfISBN > 10 Then
'Invalid ISBN
blnValidISBN = False
strDetailedErrorMsg = "The entered ISBN number can't be more than 10 digits long."
ElseIf intLengthOfISBN < 10 Then
'Invalid ISBN
blnValidISBN = False
strDetailedErrorMsg = "The entered ISBN number can't be less than 10 digits long."
End If
'Loop through each charcter
Do Until intLooper = intLengthOfISBN Or blnValidISBN = False
'Take a single character from ISBN string
strTakenChar = Mid(strEnteredISBNNumber, intLooper + 1, 1)
'Ensure character is numeric
If IsNumeric(strTakenChar) = False Then
'Make sure that it isn't the ending X if it exists
If intLooper = 9 And strTakenChar = "X" Then
& ; ;nbs p; 'X was used at end
Else
& ; ;nbs p; 'ISBN isn't valid
& ; ;nbs p; blnValidISBN = False
& ; ;nbs p; 'Set detailed error message
& ; ;nbs p;
strDetailedErrorMsg = "An invalid character was used (" &
strTakenChar & "). Numeric digits only. 'X' however can be
used as the 10th digit."
End If
End If
'Increment loop counter
intLooper = intLooper + 1
Loop
'If valid so far ensure group identifier is valid
If blnValidISBN = True Then
'Test for 1 digit identifiers (0-7)
intGroupIdentifier = CLng(Left(strEnteredISBNNumber, 1))
If intGroupIdentifier < 8 Then
blnFoundValGI = True
intGILen = 1
End If
'Test for 2 digit identifiers (80-93)
If blnFoundValGI = False Then
intGroupIdentifier = CLng(Left(strEnteredISBNNumber, 2))
If intGroupIdentifier > 79 And intGroupIdentifier < 94 Then
& ; ;nbs p; blnFoundValGI = True
& ; ;nbs p; intGILen = 2
End If
End If
'Test for 3 digit identifiers (950-987)
If blnFoundValGI = False Then
intGroupIdentifier = CLng(Left(strEnteredISBNNumber, 3))
If intGroupIdentifier > 949 And intGroupIdentifier < 987 Then
& ; ;nbs p; blnFoundValGI = True
& ; ;nbs p; intGILen = 3
End If
End If
'Test for 4 digit identifiers (9960-9987)
If blnFoundValGI = False Then
intGroupIdentifier = CLng(Left(strEnteredISBNNumber, 4))
If intGroupIdentifier > 9959 And intGroupIdentifier < 9988 Then
& ; ;nbs p; 
|