CFLib.org – Common Function Library Project

IsISBN(isbn)

Last updated May 16, 2002

author

Alex

Version: 1 | Requires: CF5 | Library: StrLib

Description:
Checks to to see if value is a valid ISBN.

Return Values:
Returns a boolean.

Example:

<cfoutput>
#isISBN("013152447X")#
</cfoutput>

Parameters:

Name Description Required
isbn ISBN string to check. Yes

Full UDF Source:

/**
 * Checks to to see if value is a valid ISBN.
 * 
 * @param isbn 	 ISBN string to check. (Required)
 * @return Returns a boolean. 
 * @author Alex (axs@arbornet.org) 
 * @version 1, May 16, 2002 
 */
function IsISBN(isbn)  {
 	var total       = 0;
  	var test        = 0;
    var check_digit = 0;
    var i = 1;
	
    if (len(isbn) neq  10) return false;
	
	test = left(isbn,9);
	check_digit = right(isbn,1);
	
    if (NOT isnumeric(test)) return false;
	
    for ( i = 1; i lt 10; i=i+1) {
		total = total + (Mid(isbn, i, 1) * i);
    }

    test = total mod 11; 

	if (test eq 10) test = "X";
			
	if (test eq check_digit) return true;
	else return false;
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson