Adyyda
Adyyda

Reputation: 335

Detect input text as ISBN EAN UPC

I want to build a input form in which a user inserts a code and depending on what is introduced, show a message like UPS (or EAN/ISBN/GTIN ) code found or This code is not valid.

Have been looked for a library that can detect something like this but had no luck? First of all, can it be done, and if yes, any tips for such library?

$('input[type="text"]').each(function() {
    $(this).rules('add', {
        messages: {
            required: "this is EAN code"
        }
    })
});
$('input[type="file"]').each(function() {
    $(this).rules('add', {
        messages: {
            required: "this is ISBN code"
        }
    })
});

Upvotes: 1

Views: 339

Answers (1)

Yannick Huber
Yannick Huber

Reputation: 617

Yes this can be done.

There are different libarys that can validate if a String is a valid EAN/ISBN/GTIN. And if the input is not a valid EAN/ISBN/GTIN than it is (by your definition) an undefined input and not valid.

You could use a combination of different libarys or check out how they work and adapt it to your specific problem.

Here are some example JavaScript libarys:

https://github.com/dominiklessel/node-barcoder An EAN/GTIN validator

https://github.com/yieme/isbnjs An ISBN JavaScript Library

Upvotes: 2

Related Questions