By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,919 Members | 1,625 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,919 IT Pros & Developers. It's quick & easy.

Input Validation for UPC Numbers

P: n/a
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

Feb 2 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Kermit Piper wrote:
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

Feb 2 '06 #2

P: n/a
JRS: In article <11*********************@g43g2000cwa.googlegroups. com>,
dated Thu, 2 Feb 2006 00:11:13 remote, seen in
news:comp.lang.javascript, Kermit Piper <di***********@hotmail.com>
posted :
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.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Feb 2 '06 #3

P: n/a
On 2006-02-02, Kermit Piper <di***********@hotmail.com> wrote:
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?


there's a way to calculate the check digit google for it you'll find it.

Bye.
Jasen
Feb 3 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.