#native_company# #native_desc#
#native_cta#

ISBN validation

By walter
on August 13, 2003

Version: 1.0

Type: Function

Category: Other

License: Artistic License

Description: This function validates ISBN-code for books.

<?php
/*
Script by Walter Ebert, without any warranty. You are free to change and redistribute this script. Publishers do not always use valid ISBN codes. An "X" is often used as the last digit. This is not permitted by the official ISBN rules.
Usage: if(validate_isbn($isbn)){ ... ;}
*/

function validate_isbn($isbn) {
	$stripped = ereg_replace("[[:space:]-]","",$isbn);
	if(ereg("[^[:digit:]]",$stripped)) {
		return false;
	}
	if(strlen($stripped)<>10) {
		return false;
	}
	for($i=0 ; $i<10 ; $i++) {
		$check = $check + (10-$i)*substr($stripped,$i,1);
	}
	$check = $check % 11;
	if(empty($check)) {
		return true;
	} else {
		return false;
	}
}
?>