K
Kermit Piper
Hello everyone,
OK, let me try and explain again please. Here is what I'm trying to do.
I have a 12-digit
(UPC-A) javascript validation script which works great. All I need now
is a similar script for 8-digit (UPC-E) type script? I don't want to
convert it to a 12-digit UPC-A before validating it as a 12-digit
number. I would prefer to just be able to calc the number, as an
8-digit number, check digit and all, just like I am currently doing
successfully with this 12-digit validation script:
<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;
}
var step2=step1*3;
step3 = 0;
for(var i=1;i<tempVar-1;i=i+2){step3=step3+(+myArray);}
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)">
I don't know what the string pattern criteria would be, all I know is I
need to be able to verify that the 8-digit number entered is a valid
format for a UPC-E number, which as I understand is based on the check
digit.
Just a straightforward script like I have above for the 12-digit
validation, only for an 8-digit validation. If this is possible I sure
would appreciate if someone could show me how.
Thanks in advance,
KP
OK, let me try and explain again please. Here is what I'm trying to do.
I have a 12-digit
(UPC-A) javascript validation script which works great. All I need now
is a similar script for 8-digit (UPC-E) type script? I don't want to
convert it to a 12-digit UPC-A before validating it as a 12-digit
number. I would prefer to just be able to calc the number, as an
8-digit number, check digit and all, just like I am currently doing
successfully with this 12-digit validation script:
<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;
}
var step2=step1*3;
step3 = 0;
for(var i=1;i<tempVar-1;i=i+2){step3=step3+(+myArray);}
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)">
I don't know what the string pattern criteria would be, all I know is I
need to be able to verify that the 8-digit number entered is a valid
format for a UPC-E number, which as I understand is based on the check
digit.
Just a straightforward script like I have above for the 12-digit
validation, only for an 8-digit validation. If this is possible I sure
would appreciate if someone could show me how.
Thanks in advance,
KP