From 8a96a0a0954b74494ca216a7ef9a84622bc25309 Mon Sep 17 00:00:00 2001 From: rlx Date: Mon, 11 Jan 2016 15:15:12 +0530 Subject: [PATCH] update formatISBN --- source/Ox/js/Format.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/source/Ox/js/Format.js b/source/Ox/js/Format.js index 805a07fb..b88a0b53 100644 --- a/source/Ox/js/Format.js +++ b/source/Ox/js/Format.js @@ -662,13 +662,16 @@ Ox.formatISBN = function(isbn, length) { ) % mod + '').replace('10', 'X'); } isbn = isbn.toUpperCase().replace(/[^\dX]/g, ''); - if (( - (isbn.length == 10 && isbn.slice(0, -1).indexOf('X') == -1) - || (isbn.length == 13 && isbn.slice(0, 3) == '978') - ) && isbn.slice(-1) == getCheckDigit(isbn)) { + if (isbn.length == 10) { + isbn = isbn.slice(0, -1).replace(/\D/g, '') + isbn.slice(-1); + } + if ( + (isbn.length == 10 || isbn.length == 13) + && isbn.slice(-1) == getCheckDigit(isbn) + ) { if (isbn.length == length) { ret = isbn - } else { + } else if (isbn.length == 10 || isbn.slice(0, 3) == '978') { isbn = isbn.length == 10 ? '978' + isbn : isbn.slice(3); ret = isbn.slice(0, -1) + getCheckDigit(isbn); }