Open main menu

Changes

Module:Authority control

938 bytes added, 18:21, 10 April 2013
+ isni and ORCID check digit validation
end
--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
function validateIsni( id )
id = string.upper( string.gsub( id, '[ %-]', '' ) ) if not string.match( id, '^%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d[%dxXdX]$' ) then return id --validation of sum?false
end
if getIsniCheckDigit( id ) ~= string.char( id:byte( 16 ) ) then return false end return idend --Returns the ISNI check digit isni must be a string where the 15 first elements are digitsfunction getIsniCheckDigit( isni ) local total = 0 for i = 1, 15 do local digit = isni:byte( i ) - 48 --Get integer value total = (total + digit) * 2 end local remainder = total % 11 local result = (12 - remainder) % 11 if result == 10 then return "X" end return tostring( result )
end
function orcidLink( id )
id = validateIsni( id )
if not id then
return false
end
id = string.sub( id, 1, 4 ) .. '-' .. string.sub( id, 5, 8 ) .. '-' .. string.sub( id, 9, 12 ) .. '-' .. string.sub( id, 13, 16 )
return '[http://orcid.org/' .. id .. ' ' .. id .. ']' .. getCatForId( 'ORCID' )
end
Anonymous user