Search code examples
javascriptsearchisbn

How do I check if an input contains an isbn using javascript


I need a script that will test an input field's contents to see if it contains an ISBN. I found a few examples of this, but none of them strip the dashes. I need this to happen or my search results don't work. I have the else part of the script working if the field doesn't have an ISBN, but can't get the ISBN test to work. Thank you in advance for any help!

function search() {
    var textboxdata = $('#search').val();
        if (textboxdata contains an ISBN number, strip it of dashes and) {
            // perform ISBN search
            document.location.href = "http://myurl?search=" + textboxdata;
        }
        else { //perform other search
        }
 }

Solution

  • Take a look at this Wikipedia article:

    http://en.wikipedia.org/wiki/International_Standard_Book_Number

    Should give you some insight into how to validate an ISBN number.