[Javascript] uses JS to check the container code.

Source: Internet
Author: User

function Verifycontainercode (strcode) {var charcode = "0123456789A"? Bcdefghijk? Lmnopqrstu? VWXYZ "; if (strcode.length! =) return False;var result = True;var num = 0;for (var i = 0; i < i++) {var idx = Cha Rcode.indexof (Strcode[i]); if (idx = =-1 | | CHARCODE[IDX] = = '? ') {result = False;break;} IDX = idx * MATH.POW (2, i); num + = idx;} num = (num%)% 10;return parseint (strcode[10]) = = num;

Container Check code Check rule:
The container number consists of 4 company codes and 7 digits (such as CBHU3202732), where the seventh digit is the check code. First, the company code is converted to a number, minus 11 and its multiples, plus divided by 11, the remaining number is the check digit. A=10 B=12 C=13 D=14 E=15 F=16 G=17 H=18 I=19 J=20 K=21 L=23 M=24 N=25 O=26 P=27 Q=28 R=29 S=30 T=31 U=32 V=34 W=35 X=36 Y= Panax Notoginseng z=38
The standard box number constitutes the basic concept: the ISO6346 (1995) standard is adopted. The standard container number consists of 11-bit codes, including three sections:

1. The first part consists of 4 English letters. The first three-digit code (owner code) mainly describes the box owner, operator, the fourth-digit code describes the type of container. Standard containers, such as cbhu, indicate that the container owners and operators are COSCO.

2. The second part consists of 6 digits. is the box registration code (registration code), which is used for a unique identity held by a container box.

3, the third part of the check code (check Digit) by the first 4 letters and 6-bit numbers through the check rule operation, to identify whether the error occurred in the checksum. That is the 11th digit. Each letter and number according to the check box number has a corresponding value for the operation. The corresponding value of the first 10 letters and numbers of the box number from 0 to Z corresponds to a number of 0 to 38, 11, 22, 33 cannot take modulus for 11, so to be removed. The corresponding value of the nth-bit box number is multiplied by 2 (N-1) (n=1,2,3...........10)

For example, the container number is CBHU3202732, its 1th digit code is c, its code value = The corresponding value of the Code X2 (1-1) =13x1=13. And so the 2nd digit code is b, its code value = The corresponding value of the Code X2 (2-1) =12x2=24 and so on to get the code value of the first 10 digits of the box number, The code value of the first 10 bits is multiplied by accumulating the first 10 bin number of the container number of the 11 modulo box to CBHU3202732, and the value of the ID of the 11th digit of the box number is 11 after the modulo of 2. And so on, you can get the check code.

[Javascript] uses JS to check the container code.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.