输入验证10,11和12位UPC代码 [英] Input validation for 10, 11 and 12-digit UPC Codes

查看:216
本文介绍了输入验证10,11和12位UPC代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我一直在搜索,谷歌搜索,搜索。找不到一个javascript到

计算10,11或12位UPC码。我只需要一个算法来计算

以验证正确的校验位。我找到了一些添加

校验位然后进行最终计算,但是我需要输入验证

将验证UPC是否正确并且正确检查

之后的数字用户只需在一个文本框中输入数字。那里必须有一些东西,但是如果我能找到的话,我会大胆的。我也会选择一个

java api,但也找不到任何一个。有一些creidt

卡格式验证器,但没有UPC。如果有人知道任何我会

非常感谢它。这是否可以通过

模数运算符和正则表达式完成?我甚至会支付第三个

派对验证工具,但我找不到任何东西!


谢谢,

KP

Hello,

I have been searching, Googling, searching. Cannot find a javascript to
calc 10, 11 or 12 digit UPC codes. I just need an algorithm that calcs
to verify the correct check digit. I have found a few that add the
check digit then do the final calc, but I need an input validation that
will verify the UPC as being correct with the correct check digit after
the user simply enteres the number in one text box. There has to be
something out there, but darned if I can find it. I''d also settle for a
java api, but couldn''t find any of those either. There''s a few creidt
card format validators, but no UPC. If anyone knows of any I would
greatly appreciate it. Is this something that can be done witht the
modulus operator and regular expressions? I''d even pay for a third
party validation tool but I can''t find ANYTHING!

Thanks,
KP

推荐答案

Kermit Piper在2006年2月7日上午12:00说:
Kermit Piper said the following on 2/7/2006 12:00 AM:
您好,

我一直在搜索,谷歌搜索,搜索。找不到一个javascript来计算10,11或12位UPC码。我只需要一个算法来计算
来验证正确的校验位。
Hello,

I have been searching, Googling, searching. Cannot find a javascript to
calc 10, 11 or 12 digit UPC codes. I just need an algorithm that calcs
to verify the correct check digit.




这只是12位数。如果你能找到一个解释10或

11的网站,请发一个网址。


它使用的样本UPC代码:0 64200 11589 6


步骤1:将奇数位置中的所有数字相加。


0 + 4 + 0 + 1 + 5 + 9 = 19

步骤2:将第1步中的金额多付为3。


3 * 19 = 57

第3步:将偶数位置中的所有数字相加。


6 + 2 + 0 + 1 + 8 = 17


步骤4:将步骤2和步骤3的结果汇总。


17 + 57 = 74

步骤5:从中减去总和下一个最高倍数10.


80 - 74 = 6 [校验位]


来自这个网站:

< URL: http:// www.cs.queensu.ca/~bradbury/c...t/upccheck.htm >


数字2点击验证UPC代码。


不知道如何& QUOT;正确"但是这个信息是。


这样做的示例脚本:


< script type =" text / javascript">

函数validateUPCCode(UPCField){

var myArray = UPCField.value.split('''');

step1 = 0;

var tempVar = myArray.length;

for(var i = 0; i< tempVar; i = i + 2){

step1 = step1 + + myArray [i];

}

var step2 = step1 * 3;

step3 = 0;

for(var i = 1; i< tempVar-1; i = i + 2){step3 = step3 +(+ myArray [i]);}

step4 = step2 + step3;

step5 =((Math.floor(step4 / 10)+ 1)* 10) - step4;

if(step5 == myArray [myArray.length-1]){alert( ''有效的UPC代码'')}

else {alert(''无效的UPC代码'')}

}


< / script>


< input type =" text" onchange =" validateUPCCode(this)">


-

Randy

comp.lang.javascript常见问题 - http://jibbering.com/faq &新闻组每周

Javascript最佳实践 - http://www.JavascriptToolbox .com / bestpractices /



This is for 12 digit only. If you can find a site that explains 10 or
11, post a URL.

Sample UPC Code it uses: 0 64200 11589 6

Step 1: Sum all of the digits in the odd positions together.

0+4+0+1+5+9 = 19

Step 2: Mutliply the sum from Step 1 by 3.

3 * 19 = 57

Step 3: Sum all of the digits in the even positions together.

6+2+0+1+8 = 17

Step 4: Sum together the results from Step 2 and Step 3.

17 + 57 = 74

Step 5: Subtract the sum from the next highest multiple of 10.

80 - 74 = 6 [check digit]

From this site:

<URL: http://www.cs.queensu.ca/~bradbury/c...t/upccheck.htm >

Number 2 Hit for "Validate UPC Code".

Not sure how "correct" that information is though.

Sample script to do that:

<script type="text/javascript">
function validateUPCCode(UPCField){
var myArray = UPCField.value.split('''');
step1 = 0;
var tempVar = myArray.length;
for (var i=0;i<tempVar;i=i+2){
step1 = step1 + +myArray[i];
}
var step2=step1*3;
step3 = 0;
for(var i=1;i<tempVar-1;i=i+2){step3=step3+(+myArray[i]);}
step4 = step2 + step3;
step5 = ((Math.floor(step4/10) + 1)*10) - step4;
if (step5 == myArray[myArray.length-1]){alert(''valid UPC Code'')}
else{alert(''invalid UPC Code'')}
}

</script>

<input type="text" onchange="validateUPCCode(this)">

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/


Kermit Piper写道:
Kermit Piper wrote:
你好,

我一直在寻找,谷歌搜索,搜索。找不到一个javascript来计算10,11或12位UPC码。我只需要一个算法来计算
以验证正确的校验位。我找到了一些添加
校验位,然后进行最终计算,但是我需要一个输入验证,
将验证UPC在用户之后使用正确的校验位是否正确只需在一个文本框中输入数字即可。那里必须有一些东西,但如果我能找到它,我就会胆怯。我也会选择一个
java api,但也找不到任何一个。有一些creidt
卡格式验证器,但没有UPC。如果有人知道我会非常欣赏它。这是可以用
模数运算符和正则表达式完成的吗?我甚至会支付第三个派对验证工具,但我找不到任何东西!
Hello,

I have been searching, Googling, searching. Cannot find a javascript to
calc 10, 11 or 12 digit UPC codes. I just need an algorithm that calcs
to verify the correct check digit. I have found a few that add the
check digit then do the final calc, but I need an input validation that
will verify the UPC as being correct with the correct check digit after
the user simply enteres the number in one text box. There has to be
something out there, but darned if I can find it. I''d also settle for a
java api, but couldn''t find any of those either. There''s a few creidt
card format validators, but no UPC. If anyone knows of any I would
greatly appreciate it. Is this something that can be done witht the
modulus operator and regular expressions? I''d even pay for a third
party validation tool but I can''t find ANYTHING!




Google首次点击计算UPC代码:


< URL:http://www.export911.com/e911/coding/digiCalc.htm>

来源在这里:


< URL:http://www.export911.com/_bCode/checDigi.js>

注:

// **版权所有

// **作者:Morris Ng

-

Rob



Very first Google hit for "calculate UPC codes":

<URL:http://www.export911.com/e911/coding/digiCalc.htm>
the source is here:

<URL:http://www.export911.com/_bCode/checDigi.js>
Note:
//**All rights reserved
//**Author: Morris Ng
--
Rob


RobG在2006年2月7日上午12:39发表以下内容:
RobG said the following on 2/7/2006 12:39 AM:
Kermit Piper写道:
Kermit Piper wrote:
你好,
以验证正确的校验位。我找到了一些添加
校验位,然后进行最终计算,但是我需要一个输入验证,
将验证UPC在用户之后使用正确的校验位是否正确只需在一个文本框中输入数字即可。那里必须有一些东西,但如果我能找到它,我就会胆怯。我也会选择一个
java api,但也找不到任何一个。有一些creidt
卡格式验证器,但没有UPC。如果有人知道我会非常欣赏它。这是可以用
模数运算符和正则表达式完成的吗?我甚至会支付第三个派对验证工具,但我找不到任何东西!
Hello,

I have been searching, Googling, searching. Cannot find a javascript to
calc 10, 11 or 12 digit UPC codes. I just need an algorithm that calcs
to verify the correct check digit. I have found a few that add the
check digit then do the final calc, but I need an input validation that
will verify the UPC as being correct with the correct check digit after
the user simply enteres the number in one text box. There has to be
something out there, but darned if I can find it. I''d also settle for a
java api, but couldn''t find any of those either. There''s a few creidt
card format validators, but no UPC. If anyone knows of any I would
greatly appreciate it. Is this something that can be done witht the
modulus operator and regular expressions? I''d even pay for a third
party validation tool but I can''t find ANYTHING!



Google首先点击计算UPC代码:

< URL:http://www.export911.com/e911/coding/digiCalc.htm>

来源在这里:

< URL:http://www.export911.com/_bCode/checDigi.js>

注意:
// **保留所有权利
// **作者:Morris Ng



Very first Google hit for "calculate UPC codes":

<URL:http://www.export911.com/e911/coding/digiCalc.htm>
the source is here:

<URL:http://www.export911.com/_bCode/checDigi.js>
Note:
//**All rights reserved
//**Author: Morris Ng




我更喜欢我的:)


-

Randy

comp.lang.javascript常见问题 - http://jibbering.com/faq&新闻组每周

Javascript最佳实践 - http://www.JavascriptToolbox .com / bestpractices /



I like mine better :)

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/


这篇关于输入验证10,11和12位UPC代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆