Jump to content

Module:Authority control/auxiliary

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by MSGJ (talk | contribs) at 12:13, 25 February 2023. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

require('strict')
local p = {}

p.validateIsni = function(id) --Validate ISNI (and ORCID) and retuns it as a 16 characters string or returns false if it's invalid. See http://support.orcid.org/knowledgebase/articles/116780-structure-of-the-orcid-identifier
	id = id:gsub( '[ %-]', '' ):upper()
	if not id:match( '^%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d[%dX]$' ) then
		return false
	end
	local total = 0
	for i = 1, 15 do
		local digit = id:byte( i ) - 48 --Get integer value
		total = (total + digit) * 2
	end
	local remainder = total % 11
	local result = (12 - remainder) % 11
	local checkdigit
	if result == 10 then
		checkdigit = 'X'
	else
		checkdigit=tostring( result )
	end
	if checkdigit ~= string.char( id:byte( 16 ) ) then
		return false
	end
	return id
end

return p