Name

isbn —

DESCRIPTION

EXAMPLES

No examples are available at this time. We do consider this a problem and will try to supply some.

NOTES

AVAILABILITY

isbn is available in Interchange versions:

5.7.0 (cvs-head)

SOURCE

Interchange 5.7.0:

Source: code/OrderCheck/isbn.oc
Lines: 61


# Copyright 2008 Interchange Development Group
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.  See the LICENSE file for details.
# 
# $Id: isbn.oc,v 1.2 2008-07-11 08:37:28 racke Exp $

CodeDef isbn OrderCheck 1
CodeDef isbn Description ISBN-10/ISBN-13 check digit verification
CodeDef isbn Routine <<EOR
sub {
my($ref, $var, $val) = @_;
$val =~ s/[^\dXx]//g;  # weed out non-digits
if ($val) {
  my @digits = split("", $val);
  my $sum = 0;
  my $check_digit = 0;
  my $modulo;

  if (@digits == 10 ) {
    # ISBN-10 number
    for(my $i=10; $i > 0; $i--) {
        my $d = $digits[10 - $i];
      if ($d =~ /[Xx]/) {
        if ($i == 1) {
          $d = 10;
        }
        else {
          return (undef, $var, errmsg("'%s' not a valid isbn number", $val));
            }
      }
      $sum += $d * $i;
    }
    return ( $sum%11 ? 0 : 1, $var, '' );
  } elsif (@digits == 13) {
    # ISBN-13/EAN number
    for (my $i = 0; $i < 12; $i++) {
      if ($i % 2) {
        $sum += 3 * $digits[$i];
      } 
      else {
        $sum += $digits[$i];
      }
    }
    
    if ($modulo = $sum % 10) {
                  $check_digit = 10 - $modulo;
          }

    if (pop(@digits) == $check_digit) {
      # verification successful
      return (1, $var, '');
    }
  }
}

return (undef, $var, errmsg("'%s' not a valid isbn number", $val));
}
EOR

AUTHORS

Interchange Development Group

SEE ALSO

DocBook! Interchange!