CFLib.org – Common Function Library Project

getISBN(BarCodeNum)

Last updated January 28, 2004

author

Amar Trivedi

Version: 1 | Requires: CF5 | Library: StrLib

Description:
UDF is useful when user needs to take scanned barcode as input and convert it to ISBN for book catalog purposes.

Return Values:
Returns a string.

Example:

<cfoutput>
     #getISBN(9780321125163)#
</cfoutput>

OUTPUT:
0321125169

Parameters:

Name Description Required
BarCodeNum Bar code number. Yes

Full UDF Source:

/**
 * Converts Barcode to valid ISBN number (without &quot;-&quot;).
 * 
 * @param BarCodeNum      Bar code number. (Required)
 * @return Returns a string. 
 * @author Amar Trivedi (atrivedi@ekomcorp.com) 
 * @version 1, January 28, 2004 
 */
function getISBN(BarCodeNum) {
  var x ='';
  var sum = 0;
  var i = 0;
  var digitsum = 0;
  var ModSum=0;

  // Barcode Must be 13 digits AND numeric 
  if(len(BarCodeNum) NEQ  13) return 0;
  if(not IsNumeric(BarCodeNum)) return 0;
  /** get rid of first 3 characters since they are  NOT used for conversion **/
  x = right(BarCodeNum,10);
  x = left(x,9);
  // loop through middle 9 digits
  for(i = 1; i LTE 9; i = i + 1) {
       digitsum = Mid( x, i, 1 ) * i;
       sum = sum + digitsum;
  }
  // check for the last letter/digit
  ModSum = sum MOD 11;
  if(ModSum EQ 10) ModSum = "x";
  return x & ModSum;
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson