diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2020-11-26 13:06:35 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2021-02-28 12:15:21 +0100 |
commit | eb7e96c07ad61a6e66fa8fd94f80fa317a99afb0 (patch) | |
tree | 32524e3090ec9ab19d15da5aa8f82b713597f0dd /ishtar_common/static/js/ishtar.js | |
parent | 1a64a5f096f1d34c5526ca64b963588feef10add (diff) | |
download | Ishtar-eb7e96c07ad61a6e66fa8fd94f80fa317a99afb0.tar.bz2 Ishtar-eb7e96c07ad61a6e66fa8fd94f80fa317a99afb0.zip |
Refactor custom widgets templates - ISSN/ISBN check
Diffstat (limited to 'ishtar_common/static/js/ishtar.js')
-rw-r--r-- | ishtar_common/static/js/ishtar.js | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/ishtar_common/static/js/ishtar.js b/ishtar_common/static/js/ishtar.js index 655a91eb4..fcaa73053 100644 --- a/ishtar_common/static/js/ishtar.js +++ b/ishtar_common/static/js/ishtar.js @@ -1796,3 +1796,63 @@ var render_stats = function(stats_values, name){ jqvalues, stats_options ); }; + +var is_valid_isbn = function(str) { + var sum, weight, digit, check, i; + + str = str.replace(/[^0-9X]/gi, ''); + + if (str.length != 10 && str.length != 13) { + return false; + } + + if (str.length == 13) { + sum = 0; + for (i = 0; i < 12; i++) { + digit = parseInt(str[i]); + if (i % 2 == 1) { + sum += 3*digit; + } else { + sum += digit; + } + } + check = (10 - (sum % 10)) % 10; + return (check == str[str.length-1]); + } + + if (str.length == 10) { + weight = 10; + sum = 0; + for (i = 0; i < 9; i++) { + digit = parseInt(str[i]); + sum += weight*digit; + weight--; + } + check = (11 - (sum % 11)) % 11 + if (check == 10) { + check = 'X'; + } + return (check == str[str.length-1].toUpperCase()); + } +} + +var is_valid_issn = function(str) { + var sum, weight, digit, check, i; + + str = str.replace(/[^0-9X]/gi, ''); + + if (str.length != 8) { + return false; + } + + sum = 0; + for (i = 0; i < 7; i++) { + digit = parseInt(str[i]); + sum += digit * (8 - i) + } + check = 11 - sum % 11; + if (check == 10) { + check = 'X'; + } + return (check == str[str.length-1].toUpperCase()); +} |