Modul:Check isxn: Unterschied zwischen den Versionen
fix return value
(X;) |
imported>Frietjes (fix return value) |
||
| Zeile 52: | Zeile 52: | ||
local function check_isbn( isbn_str, error_string ) | local function check_isbn( isbn_str, error_string ) | ||
if nil ~= isbn_str:match("[^%s-0-9X]") then | if nil ~= isbn_str:match("[^%s-0-9X]") then -- fail if isbn_str contains anything but digits, hyphens, or the uppercase X | ||
return error_string; | |||
end | |||
isbn_str = isbn_str:gsub( "-", "" ):gsub( " ", "" ); -- remove hyphens and spaces | isbn_str = isbn_str:gsub( "-", "" ):gsub( " ", "" ); -- remove hyphens and spaces | ||
local len = isbn_str:len(); | local len = isbn_str:len(); | ||
| Zeile 61: | Zeile 63: | ||
if len == 10 then | if len == 10 then | ||
if isbn_str:match( "^%d*X?$" ) == nil then return | if isbn_str:match( "^%d*X?$" ) == nil then | ||
return error_string; | |||
end | |||
return is_valid_isxn(isbn_str, 10) and '' or error_string; | return is_valid_isxn(isbn_str, 10) and '' or error_string; | ||
else | else | ||
local temp = 0; | local temp = 0; | ||
if isbn_str:match( "^97[89]%d*$" ) == nil then | if isbn_str:match( "^97[89]%d*$" ) == nil then -- isbn13 begins with 978 or 979; ismn begins with 979 | ||
return error_string; | |||
end | |||
return is_valid_isxn_13 (isbn_str) and '' or error_string; | return is_valid_isxn_13 (isbn_str) and '' or error_string; | ||
end | end | ||