Input Validation for UPC Numbers

K

Kermit Piper

Hello,

I have been searching and searching for a js function that can check
whether or not a UPC code that is entered is a valid format. I don't
expect the correct UPC code in relation to the actual product (although
we hope that is accurate), but at least check that the number entered
is in fact a valid UPC code, just like they do for credit cards. I need
this for UPC code from 8 to 13 digits in length. I found a couple
things but they didn't seem to work. They added a check digit which
didn't match the check digit on the UPC codes I got off an actual
product. Is there something out there that doesn't have to add a check
digit and that can just take the whole UPC number and check whether
it's valid or not?

Thanks,
KP
 
M

mick white

Kermit said:
Hello,

I have been searching and searching for a js function that can check
whether or not a UPC code that is entered is a valid format. I don't
expect the correct UPC code in relation to the actual product (although
we hope that is accurate), but at least check that the number entered
is in fact a valid UPC code, just like they do for credit cards. I need
this for UPC code from 8 to 13 digits in length. I found a couple
things but they didn't seem to work. They added a check digit which
didn't match the check digit on the UPC codes I got off an actual
product. Is there something out there that doesn't have to add a check
digit and that can just take the whole UPC number and check whether
it's valid or not?

Thanks,
KP
function looksLikeUPC(val){return /^\d{8,13}$/.test(val);}

Very rudimentary, though.
Mick
 
D

Dr John Stockton

JRS: In article <[email protected]>,
dated Thu, 2 Feb 2006 00:11:13 remote, seen in
I have been searching and searching for a js function that can check
whether or not a UPC code that is entered is a valid format. I don't
expect the correct UPC code in relation to the actual product (although
we hope that is accurate), but at least check that the number entered
is in fact a valid UPC code, just like they do for credit cards. I need
this for UPC code from 8 to 13 digits in length. I found a couple
things but they didn't seem to work. They added a check digit which
didn't match the check digit on the UPC codes I got off an actual
product. Is there something out there that doesn't have to add a check
digit and that can just take the whole UPC number and check whether
it's valid or not?

Find us the specification for a UPC product code, and something could be
written.

General validation : <URL:http://www.merlyn.demon.co.uk/js-valid.htm>
ISBN validation : <URL:http://www.merlyn.demon.co.uk/js-misc0.htm>

For some systems, it's easiest to compute validity /en bloc/
For some systems, it's easiest to compute the check data needed for the
real data.
For some systems, both are easy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,056
Messages
2,570,441
Members
47,119
Latest member
NoeliaIrby

Latest Threads

Top