<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="zh">
	<id>https://gf-ogas.wiki/index.php?action=history&amp;feed=atom&amp;title=Module%3AISBN</id>
	<title>Module:ISBN - 版本历史</title>
	<link rel="self" type="application/atom+xml" href="https://gf-ogas.wiki/index.php?action=history&amp;feed=atom&amp;title=Module%3AISBN"/>
	<link rel="alternate" type="text/html" href="https://gf-ogas.wiki/index.php?title=Module:ISBN&amp;action=history"/>
	<updated>2026-05-16T23:44:23Z</updated>
	<subtitle>本wiki上该页面的版本历史</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://gf-ogas.wiki/index.php?title=Module:ISBN&amp;diff=210&amp;oldid=prev</id>
		<title>秋绘君：​创建页面，内容为“local module = {}  ----------------------------&lt; IS _ V A L I D _ I S X N &gt;-----------------------------------------------------   ISBN-10 and ISSN validator code calculates checksum across all isbn/issn digits including the check digit. ISBN-13 is checked in check_isbn(). If the number is valid the result will be 0. Before calling this function, issbn/issn must be checked for length and stripped of dashes, spaces and other non-isxn characters.      local f…”</title>
		<link rel="alternate" type="text/html" href="https://gf-ogas.wiki/index.php?title=Module:ISBN&amp;diff=210&amp;oldid=prev"/>
		<updated>2026-01-22T13:38:36Z</updated>

		<summary type="html">&lt;p&gt;创建页面，内容为“local module = {}  --[[--------------------------&amp;lt; IS _ V A L I D _ I S X N &amp;gt;-----------------------------------------------------   ISBN-10 and ISSN validator code calculates checksum across all isbn/issn digits including the check digit. ISBN-13 is checked in check_isbn(). If the number is valid the result will be 0. Before calling this function, issbn/issn must be checked for length and stripped of dashes, spaces and other non-isxn characters.   ]]   local f…”&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新页面&lt;/b&gt;&lt;/p&gt;&lt;div&gt;local module = {}&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; IS _ V A L I D _ I S X N &amp;gt;-----------------------------------------------------&lt;br /&gt;
 &lt;br /&gt;
ISBN-10 and ISSN validator code calculates checksum across all isbn/issn digits including the check digit. ISBN-13 is checked in check_isbn().&lt;br /&gt;
If the number is valid the result will be 0. Before calling this function, issbn/issn must be checked for length and stripped of dashes,&lt;br /&gt;
spaces and other non-isxn characters.&lt;br /&gt;
 &lt;br /&gt;
]]&lt;br /&gt;
 &lt;br /&gt;
local function is_valid_isxn (isxn_str, len)&lt;br /&gt;
	local temp = 0;&lt;br /&gt;
	isxn_str = { isxn_str:byte(1, len) };	-- make a table of byte values &amp;#039;0&amp;#039; → 0x30 .. &amp;#039;9&amp;#039;  → 0x39, &amp;#039;X&amp;#039; → 0x58&lt;br /&gt;
	len = len+1;							-- adjust to be a loop counter&lt;br /&gt;
	for i, v in ipairs( isxn_str ) do		-- loop through all of the bytes and calculate the checksum&lt;br /&gt;
		if v == string.byte( &amp;quot;X&amp;quot; ) then		-- if checkdigit is X (compares the byte value of &amp;#039;X&amp;#039; which is 0x58)&lt;br /&gt;
			temp = temp + 10*( len - i );	-- it represents 10 decimal&lt;br /&gt;
		else&lt;br /&gt;
			temp = temp + tonumber( string.char(v) )*(len-i);&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return temp % 11 == 0;					-- returns true if calculation result is zero&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
--[[--------------------------&amp;lt; IS _ V A L I D _ I S X N  _ 1 3 &amp;gt;----------------------------------------------&lt;br /&gt;
 &lt;br /&gt;
ISBN-13 and ISMN validator code calculates checksum across all 13 isbn/ismn digits including the check digit.&lt;br /&gt;
If the number is valid, the result will be 0. Before calling this function, isbn-13/ismn must be checked for length&lt;br /&gt;
and stripped of dashes, spaces and other non-isxn-13 characters.&lt;br /&gt;
 &lt;br /&gt;
]]&lt;br /&gt;
 &lt;br /&gt;
local function is_valid_isxn_13 (isxn_str)&lt;br /&gt;
	local temp = 0;&lt;br /&gt;
	&lt;br /&gt;
	isxn_str = { isxn_str:byte(1, 13) };										-- make a table of byte values &amp;#039;0&amp;#039; → 0x30 .. &amp;#039;9&amp;#039;  → 0x39&lt;br /&gt;
	for i, v in ipairs( isxn_str ) do&lt;br /&gt;
		temp = temp + (3 - 2*(i % 2)) * tonumber( string.char(v) );				-- multiply odd index digits by 1, even index digits by 3 and sum; includes check digit&lt;br /&gt;
	end&lt;br /&gt;
	return temp % 10 == 0;														-- sum modulo 10 is zero when isbn-13/ismn is correct&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
--[[--------------------------&amp;lt; C H E C K _ I S B N &amp;gt;------------------------------------------------------------&lt;br /&gt;
 &lt;br /&gt;
Determines whether an ISBN string is valid&lt;br /&gt;
 &lt;br /&gt;
]]&lt;br /&gt;
 &lt;br /&gt;
function module.check_isbn( frame )&lt;br /&gt;
	local isbn_str = mw.text.trim(frame.args[1] or &amp;#039;&amp;#039;)&lt;br /&gt;
	if nil ~= isbn_str:match(&amp;quot;[^%s-0-9X]&amp;quot;) then return false; end	-- fail if isbn_str contains anything but digits, hyphens, or the uppercase X&lt;br /&gt;
	isbn_str = isbn_str:gsub( &amp;quot;-&amp;quot;, &amp;quot;&amp;quot; ):gsub( &amp;quot; &amp;quot;, &amp;quot;&amp;quot; );			-- remove hyphens and spaces&lt;br /&gt;
	local len = isbn_str:len();&lt;br /&gt;
 &lt;br /&gt;
	if len ~= 10 and len ~= 13 then&lt;br /&gt;
		return false;&lt;br /&gt;
	end&lt;br /&gt;
 &lt;br /&gt;
	if len == 10 then&lt;br /&gt;
		if isbn_str:match( &amp;quot;^%d*X?$&amp;quot; ) == nil then return false; end&lt;br /&gt;
		return is_valid_isxn(isbn_str, 10);&lt;br /&gt;
	else&lt;br /&gt;
		local temp = 0;&lt;br /&gt;
		if isbn_str:match( &amp;quot;^97[89]%d*$&amp;quot; ) == nil then return false; end		-- isbn13 begins with 978 or 979; ismn begins with 979&lt;br /&gt;
		return is_valid_isxn_13 (isbn_str);&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return module&lt;/div&gt;</summary>
		<author><name>秋绘君</name></author>
	</entry>
</feed>