Skip to content

Instantly share code, notes, and snippets.

@oscarmorrison
Last active May 1, 2022 00:41
Show Gist options
  • Save oscarmorrison/3744fa216dcfdb3d0bcb to your computer and use it in GitHub Desktop.
Save oscarmorrison/3744fa216dcfdb3d0bcb to your computer and use it in GitHub Desktop.
var isbns = ['ISBN 0-330-28498-3',
'ISBN 1-58182-008-9',
'ISBN 2-226-05257-7',
'ISBN 3-7965-1900-8',
'ISBN 4-19-830127-1',
'ISBN 5-85270-001-0',
'ISBN 978-600-119-125-1',
'978-601-7151-13-3',
'ISBN 978-602-8328-22-7',
'ISBN 978-603-500-045-1',
'ISBN 605-384-057-2',
'ISBN 978-606-8126-35-7',
'ISBN 978-607-455-035-1',
'ISBN 978-608-203-023-4',
'ISBN 978-612-45165-9-7',
'ISBN 978-614-404-018-8',
'ISBN 978-615-5014-99-4',
'ISBN 7-301-10299-2',
'ISBN 80-85983-44-3',
'81-7215-399-6',
'82-530-0983-6',
'ISBN 83-08-01587-5',
'ISBN 84-86546-08-7',
'ISBN 85-7531-015-1',
'ISBN 86-341-0846-5',
'ISBN 87-595-2277-1',
'88-04-47328-2',
'ISBN 90-5691-187-2',
'ISBN 91-1-811692-2',
'ISBN 92-67-10370-9',
'ISBN 93-5025-214-7',
'ISBN 950-04-0442-7',
'ISBN 951-0-11369-7',
'ISBN 952-471-294-6',
'ISBN 953-157-105-8',
'ISBN 954-430-603-X',
'ISBN 955-20-3051-X',
'ISBN 956-7291-48-9',
'ISBN 957-01-7429-3',
'ISBN 958-04-6278-X',
'ISBN 959-10-0363-3',
'ISBN 961-6403-23-0',
'ISBN 962-04-0195-6',
'ISBN 963-7971-51-3',
'ISBN 964-6194-70-2',
'ISBN 965-359-002-2',
'ISBN 966-95440-5-X',
'ISBN 967-978-753-2',
'ISBN 968-6031-02-2',
'ISBN 969-35-2020-3',
'ISBN 970-20-0242-7',
'ISBN 971-8845-10-0',
'ISBN 972-37-0274-6',
'ISBN 973-43-0179-9',
'ISBN 974-85854-7-6',
'ISBN 975-293-381-5',
'ISBN 976-640-140-3',
'ISBN 977-734-520-8',
'ISBN 979-553-483-1',
'ISBN 980-01-0194-2',
'ISBN 981-3018-39-9',
'ISBN 982-301-001-3',
'ISBN 983-52-0157-9',
'ISBN 984-458-089-7',
'ISBN 986-417-191-7',
'ISBN 987-98184-2-3',
'ISBN 978-988-00-3827-3',
'ISBN 978-9928400529',
'ISBN 978-9929801646',
'ISBN 978-9930943106']
function checkISBN(query){
var rgx_10 = /^(?:ISBN(?:-10)?:?\ )?(?=[0-9X]{10}$|(?=(?:[0-9]+[-\ ]){3})[-\ 0-9X]{13}$)[0-9]{1,5}[-\ ]?[0-9]+[-\ ]?[0-9]+[-\ ]?[0-9X]$/
var rgx_13 = /^(?:ISBN(?:-13)?:?\ )?(?=[0-9]{13}$|(?=(?:[0-9]+[-\ ]){4})[-\ 0-9]{17}$)97[89][-\ ]?[0-9]{1,5}[-\ ]?[0-9]+[-\ ]?[0-9]+[-\ ]?[0-9]$/
return rgx_10.test(query) || rgx_13.test(query);
}
isbns.map(function (isbn) {
console.log(isbn);
console.log(checkISBN(isbn));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment