summaryrefslogtreecommitdiff
path: root/ishtar_common/static
diff options
context:
space:
mode:
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
commit30bf32d6768f3c013b44e1ed76d94f9954d6e565 (patch)
tree32524e3090ec9ab19d15da5aa8f82b713597f0dd /ishtar_common/static
parentfda191a63534f13470844bf5d7462f260801e318 (diff)
downloadIshtar-30bf32d6768f3c013b44e1ed76d94f9954d6e565.tar.bz2
Ishtar-30bf32d6768f3c013b44e1ed76d94f9954d6e565.zip
Refactor custom widgets templates - ISSN/ISBN check
Diffstat (limited to 'ishtar_common/static')
-rw-r--r--ishtar_common/static/js/ishtar.js60
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());
+}