Module:Check isxn: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
No edit summary |
add error string |
||
Line 51: | Line 51: | ||
]] |
]] |
||
function check_isbn( isbn_str ) |
function check_isbn( isbn_str, error_string ) |
||
if nil ~= isbn_str:match("[^%s-0-9X]") then return false; end -- fail if isbn_str contains anything but digits, hyphens, or the uppercase X |
if nil ~= isbn_str:match("[^%s-0-9X]") then return false; end -- fail if isbn_str contains anything but digits, hyphens, or the uppercase X |
||
isbn_str = isbn_str:gsub( "-", "" ):gsub( " ", "" ); -- remove hyphens and spaces |
isbn_str = isbn_str:gsub( "-", "" ):gsub( " ", "" ); -- remove hyphens and spaces |
||
Line 57: | Line 57: | ||
if len ~= 10 and len ~= 13 then |
if len ~= 10 and len ~= 13 then |
||
return |
return error_string; |
||
end |
end |
||
if len == 10 then |
if len == 10 then |
||
if isbn_str:match( "^%d*X?$" ) == nil then return false; end |
if isbn_str:match( "^%d*X?$" ) == nil then return false; end |
||
return is_valid_isxn(isbn_str, 10) and '' or |
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 return false; end -- isbn13 begins with 978 or 979; ismn begins with 979 |
if isbn_str:match( "^97[89]%d*$" ) == nil then return false; end -- isbn13 begins with 978 or 979; ismn begins with 979 |
||
return is_valid_isxn_13 (isbn_str) and '' or |
return is_valid_isxn_13 (isbn_str) and '' or error_string; |
||
end |
end |
||
end |
end |
||
Line 78: | Line 78: | ||
]] |
]] |
||
function check_ismn (id) |
function check_ismn (id, error_string) |
||
local text; |
local text; |
||
local valid_ismn = true; |
local valid_ismn = true; |
||
Line 90: | Line 90: | ||
end |
end |
||
return valid_ismn and '' or |
return valid_ismn and '' or error_string |
||
end |
end |
||
Line 106: | Line 106: | ||
]] |
]] |
||
function check_issn(id) |
function check_issn(id, error_string) |
||
local issn_copy = id; -- save a copy of unadulterated issn; use this version for display if issn does not validate |
local issn_copy = id; -- save a copy of unadulterated issn; use this version for display if issn does not validate |
||
local text; |
local text; |
||
Line 119: | Line 119: | ||
end |
end |
||
return valid_issn and '' or |
return valid_issn and '' or error_string |
||
end |
end |
||
function p.check_isbn(frame) |
function p.check_isbn(frame) |
||
return check_issn(frame.args[1] or frame:getParent().args[1]) |
return check_issn(frame.args[1] or frame:getParent().args[1], frame.args['error'] or frame:getParent().args['error'] or 'error') |
||
end |
end |
||
function p.check_ismn(frame) |
function p.check_ismn(frame) |
||
return check_issn(frame.args[1] or frame:getParent().args[1]) |
return check_issn(frame.args[1] or frame:getParent().args[1], frame.args['error'] or frame:getParent().args['error'] or 'error') |
||
end |
end |
||
function p.check_issn(frame) |
function p.check_issn(frame) |
||
return check_issn(frame.args[1] or frame:getParent().args[1]) |
return check_issn(frame.args[1] or frame:getParent().args[1], frame.args['error'] or frame:getParent().args['error'] or 'error') |
||
end |
end |
||