Importer, Bürokraten, Moderatoren (CommentStreams), Strukturierte-Diskussionen-Bots, Oberflächenadministratoren, Push-Abonnementverwalter, Oversighter, Administratoren, Kampagnenbearbeiter (Hochladeassistent)
855
Bearbeitungen
(test issn for correct format;) |
K (14 Versionen von wikivoyage:Modul:Check_isxn importiert) |
||
| (6 dazwischenliegende Versionen von 3 Benutzern werden nicht angezeigt) | |||
| Zeile 51: | Zeile 51: | ||
]] | ]] | ||
function p._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 | ||
| Zeile 78: | Zeile 84: | ||
]] | ]] | ||
function p._check_ismn (id, error_string) | |||
local text; | local text; | ||
local valid_ismn = true; | local valid_ismn = true; | ||
| Zeile 106: | Zeile 112: | ||
]] | ]] | ||
function p._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; | ||
local valid_issn = true; | local valid_issn = true; | ||
if not id:match ('^%d%d%d%d%-%d%d%d% | if not id:match ('^%d%d%d%d%-%d%d%d[%dX]$') then | ||
return error_string; | return error_string; | ||
end | end | ||
| Zeile 130: | Zeile 136: | ||
function p.check_isbn(frame) | function p.check_isbn(frame) | ||
return | return p._check_isbn(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 | return p._check_ismn(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 | return p._check_issn(frame.args[1] or frame:getParent().args[1], frame.args['error'] or frame:getParent().args['error'] or 'error') | ||
end | end | ||
return p | return p | ||