require('strict');
--
local function bibcode (id) local err_type; local year;
if 19 ~= id:len then err_type = 'length'; else year = id:match ("^(%d%d%d%d)[%a][%w&%.][%w&%.][%w&%.][%w.]+[%a%.]$") -- if not year then -- if nil then no pattern match err_type = 'value'; -- so value error else local next_year = tonumber(os.date ('%Y'))+1; -- get the current year as a number and add one for next year year = tonumber (year); -- convert year portion of bibcode to a number if (1000 > year) or (year > next_year) then err_type = 'year'; -- year out of bounds end if id:find('&%.') then err_type = 'journal'; -- journal abbreviation must not have '&.' (if it does its missing a letter) end end end
return err_type;end
--[=[-------------------------< E N T R Y P O I N T S >------------------------------------------------------ This module is mostly a copy of the bibcode validation used in [[Module:Citation/CS1]]
call this module with: where is the bibcode
]=]
local function check_bibcode (frame) local err_type = bibcode (mw.text.trim (frame.args[1])); -- trim leading and trailing white space before evaluation if err_type then return '
Check bibcode: ' .. err_type .. ' (help)'; end return ; -- return empty string when bibcode appears to be validend----------------------------< E X P O R T E D F U N C T I O N S >------------------------------------------
return