| Modul Lua ini digunakan pada sekitar 19.000 halaman dan perubahannya kemungkinan memicu perubahan massal pada semua halaman yang menggunakannya. Uji cobalah di subhalaman /bak pasir atau /kasus uji Modul:Check isxn, atau bak pasir modul Anda. Pertimbangkan untuk mendiskusikan perubahan di halaman pembicaraan sebelum mengimplementasikannya. |
| Modul ini dilindungi. Modul ini sangat mencolok yang digunakan oleh banyak halaman, atau sangat sering disubstitusikan. Karena vandalisme atau kesalahan akan mempengaruhi banyak halaman, dan suntingan kecil dapat memberi beban besar pada server, modul ini dilindungi dari penyuntingan. |
Modul ini dapat digunakan untuk memvalidasi ISBN, ISMN dan ISSN.
PenggunaanPenggunaan
Untuk ISBN,
{{#invoke:check isxn|check_isbn|978-0-12-345678-9|error={{error-small|ISBN tidak valid}}}}
Untuk ISMN,
{{#invoke:check isxn|check_ismn|979-0-1234567-8-9|error={{error-small|ISMN tidak valid}}}}
Untuk ISSN,
{{#invoke:check isxn|check_issn|1234-5678|error={{error-small|ISSN tidak valid}}}}
ContohContoh
{{#invoke:check isxn|check_isbn|978-3-16-148410-0|error={{error-small|ISBN tidak valid}}}}→{{#invoke:check isxn|check_isbn|978-0-12-345678-9|error={{error-small|ISBN tidak valid}}}}→ pemanggilan templat memerlukan parameter template_name{{#invoke:check isxn|check_isbn|ISBN 978-3-16-148410-0|error={{error-small|ISBN tidak valid}}}}→ pemanggilan templat memerlukan parameter template_name{{#invoke:check isxn|check_ismn|979-0-9016791-7-7|error={{error-small|ISMN tidak valid}}}}→{{#invoke:check isxn|check_ismn|979-0-1234567-8-9|error={{error-small|ISMN tidak valid}}}}→ ISMN tidak valid{{#invoke:check isxn|check_issn|1234-5679|error={{error-small|ISSN tidak valid}}}}→{{#invoke:check isxn|check_issn|1234-5678|error={{error-small|ISSN tidak valid}}}}→ ISSN tidak valid
Dokumentasi di atas ditransklusikan dari Modul:Check isxn/doc. (sunting | riwayat)
Penyunting dapat melakukan uji coba pada halaman bak pasir (buat | cermin) dan kasus uji (buat) modul ini.
Subhalaman modul ini.
Penyunting dapat melakukan uji coba pada halaman bak pasir (buat | cermin) dan kasus uji (buat) modul ini.
Subhalaman modul ini.
-- This template is a copy of the ISXN validation code from [[Module:Citation/CS1]] -- which allows for validating ISBN, ISMN, and ISSN without invoking a citation template localp={} --[[--------------------------< E R R _ M S G _ S U P L _ T >-------------------------------------------------- error message supplements for check_isbn(); adapted from a similarly named table at Module:Citation/CS1/Configuration ]] localerr_msg_supl_t={ ['char']='karakter tidak valid', ['check']='checksum', ['form']='formulir tidak valid', ['group']='ID grup tidak valid', ['length']='panjang', ['prefix']='prefix tidak valid', } --[[--------------------------< IS _ V A L I D _ I S X N >----------------------------------------------------- ISBN-10 and ISSN validator code calculates checksum across all isbn/issn digits including the check digit. ISBN-13 is checked in check_isbn(). If the number is valid the result will be 0. Before calling this function, issbn/issn must be checked for length and stripped of dashes, spaces and other non-isxn characters. ]] localfunctionis_valid_isxn(isxn_str,len) localtemp=0; isxn_str={isxn_str:byte(1,len)};-- make a table of byte values '0' → 0x30 .. '9' → 0x39, 'X' → 0x58 len=len+1;-- adjust to be a loop counter fori,vinipairs(isxn_str)do-- loop through all of the bytes and calculate the checksum ifv==string.byte("X")then-- if checkdigit is X (compares the byte value of 'X' which is 0x58) temp=temp+10*(len-i);-- it represents 10 decimal else temp=temp+tonumber(string.char(v))*(len-i); end end returntemp%11==0;-- returns true if calculation result is zero end --[[--------------------------< IS _ V A L I D _ I S X N _ 1 3 >---------------------------------------------- ISBN-13 and ISMN validator code calculates checksum across all 13 isbn/ismn digits including the check digit. If the number is valid, the result will be 0. Before calling this function, isbn-13/ismn must be checked for length and stripped of dashes, spaces and other non-isxn-13 characters. ]] localfunctionis_valid_isxn_13(isxn_str) localtemp=0; isxn_str={isxn_str:byte(1,13)};-- make a table of byte values '0' → 0x30 .. '9' → 0x39 fori,vinipairs(isxn_str)do temp=temp+(3-2*(i%2))*tonumber(string.char(v));-- multiply odd index digits by 1, even index digits by 3 and sum; includes check digit end returntemp%10==0;-- sum modulo 10 is zero when isbn-13/ismn is correct end --[[--------------------------< C H E C K _ I S B N >------------------------------------------------------------ Determines whether an ISBN string is valid ]] localfunctioncheck_isbn(isbn_str,frame) localfunctionreturn_result(check,err_type)-- local function to render the various error returns ifnotcheckthen-- <check> false when there is an error localtemplate=((frame.args.template_nameand''~=frame.args.template_name)andframe.args.template_name)ornil;-- get template name ifnottemplatethen return'<span class="error" style="font-size:100%"> pemanggilan templat memerlukan parameter template_name</span>'; end localout_t={'<span class="error" style="font-size:100%">'};-- open the error message span table.insert(out_t,' Galat parameter pada {{[[Templat:');-- open 'template' markup; open wikilink with Template namespace table.insert(out_t,template);-- template name wikilink table.insert(out_t,'|');-- its pipe table.insert(out_t,template);-- wikilink label table.insert(out_t,']]}}: ');-- close wikilink; close 'template' markup table.insert(out_t,err_type);-- type of isbn error table.insert(out_t,'</span>')-- close the error message span if0==mw.title.getCurrentTitle().namespacethen-- categorize only when this template is used in mainspace localcategory=table.concat({'[[Kategori:Halaman dengan galat ISBN]]'}); table.insert(out_t,category); end returntable.concat(out_t);-- make a big string and done end return'';-- no error, return an empty string end ifnil~=isbn_str:match('[^%s-0-9X]')then returnreturn_result(false,err_msg_supl_t.char);-- fail if isbn_str contains anything but digits, hyphens, or the uppercase X end localid=isbn_str:gsub('[%s-]','');-- remove hyphens and whitespace locallen=id:len(); iflen~=10andlen~=13then returnreturn_result(false,err_msg_supl_t.length);-- fail if incorrect length end iflen==10then ifid:match('^%d*X?$')==nilthen-- fail if isbn_str has 'X' anywhere but last position returnreturn_result(false,err_msg_supl_t.form); end ifid:find('^63[01]')then-- 630xxxxxxx and 631xxxxxxx are (apparently) not valid isbn group ids but are used by amazon as numeric identifiers (asin) <- Tolong temukan awalan untuk Gramedia atau sejenisnya returnreturn_result(false,err_msg_supl_t.group);-- fail if isbn-10 begins with 630/1 end returnreturn_result(is_valid_isxn(id,10),err_msg_supl_t.check);-- pass if isbn-10 is numerically valid (checksum) else ifid:match('^%d+$')==nilthen returnreturn_result(false,err_msg_supl_t.char);-- fail if ISBN-13 is not all digits end ifid:match('^97[89]%d*$')==nilthen returnreturn_result(false,err_msg_supl_t.prefix);-- fail when ISBN-13 does not begin with 978 or 979 end ifid:match('^9790')then returnreturn_result(false,err_msg_supl_t.group);-- group identifier '0' is reserved to ISMN end returnreturn_result(is_valid_isxn_13(id),err_msg_supl_t.check);-- pass if isbn-10 is numerically valid (checksum) end end --[[--------------------------< C H E C K _ I S M N >------------------------------------------------------------ Determines whether an ISMN string is valid. Similar to isbn-13, ismn is 13 digits begining 979-0-... and uses the same check digit calculations. See http://www.ismn-international.org/download/Web_ISMN_Users_Manual_2008-6.pdf section 2, pages 9–12. ]] localfunctioncheck_ismn(id,error_string) localtext; localvalid_ismn=true; id=id:gsub("[%s-–]","");-- strip spaces, hyphens, and endashes from the ismn if13~=id:len()orid:match("^9790%d*$")==nilthen-- ismn must be 13 digits and begin 9790 valid_ismn=false; else valid_ismn=is_valid_isxn_13(id);-- validate ismn end returnvalid_ismnand''orerror_string end --[[--------------------------< I S S N >---------------------------------------------------------------------- Validate and format an issn. This code fixes the case where an editor has included an ISSN in the citation but has separated the two groups of four digits with a space. When that condition occurred, the resulting link looked like this: |issn=0819 4327 gives: [http://www.worldcat.org/issn/0819 4327 0819 4327] -- can't have spaces in an external link This code now prevents that by inserting a hyphen at the issn midpoint. It also validates the issn for length and makes sure that the checkdigit agrees with the calculated value. Incorrect length (8 digits), characters other than 0-9 and X, or checkdigit / calculated value mismatch will all cause a check issn error message. ]] localfunctioncheck_issn(id,error_string) localissn_copy=id;-- save a copy of unadulterated issn; use this version for display if issn does not validate localtext; localvalid_issn=true; ifnotid:match('^%d%d%d%d%-%d%d%d[%dX]$')then returnerror_string; end id=id:gsub("[%s-–]","");-- strip spaces, hyphens, and endashes from the issn if8~=id:len()ornil==id:match("^%d*X?$")then-- validate the issn: 8 digits long, containing only 0-9 or X in the last position valid_issn=false;-- wrong length or improper character else valid_issn=is_valid_isxn(id,8);-- validate issn end returnvalid_issnand''orerror_string end ------------------------------< E N T R Y P O I N T S >--------------------------------------------------==== functionp.check_isbn(frame) returncheck_isbn(frame.args[1]orframe:getParent().args[1],frame) end functionp.check_ismn(frame) returncheck_ismn(frame.args[1]orframe:getParent().args[1],frame.args['error']orframe:getParent().args['error']or'error') end functionp.check_issn(frame) returncheck_issn(frame.args[1]orframe:getParent().args[1],frame.args['error']orframe:getParent().args['error']or'error') end returnp