Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - VBScript ISBN Validation
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

VBScript ISBN Validation

 Post Reply Post Reply
Author
Gullanian View Drop Down
Senior Member
Senior Member
Avatar

Joined: 04 January 2002
Location: England
Status: Offline
Points: 4373
Post Options Post Options   Thanks (0) Thanks(0)   Quote Gullanian Quote  Post ReplyReply Direct Link To This Post Topic: VBScript ISBN Validation
    Posted: 25 November 2004 at 11:12pm
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; 
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.