소프트웨어에서의 바코드 유효성 검사 및 오류 처리
Implementing barcode validation in application code — check digit verification, format validation, error handling, and user feedback patterns.
Barcode Validation Software: Ensuring Data Integrity
Barcode validation software checks that barcode data conforms to format specifications, business rules, and regulatory requirements before the barcode is printed or after it is scanned. Validation prevents costly errors like rejected shipments, regulatory violations, and scanning failures.
Validation vs Verification
These terms are often confused:
- Validation: Checks that the data content is correct (valid GS1 Standards & Identifiers">GTIN, proper AI formatting, correct check digit)
- Verification: Measures the physical print quality of the barcode symbol (ISO/IEC 15416" data-definition="International standard grading linear barcode print quality A-F." data-category="Printing & Quality">ISO/IEC 15416 / 15415 grading)
Both are important, but this guide focuses on data validation.
Check Digit Validation
The most basic validation: recalculate the check digit and compare it to the one in the barcode.
| Symbology | Algorithm |
|---|---|
| EAN-13 / UPC | Modulo 10 (weighted 1,3) |
| Code 128 | Code 128 check digit using weighted positional values mod 103." data-category="Check Digit & Validation">Modulo 103 (weighted) |
| Code 39 | Code 39 check digit algorithm dividing character sums by 43." data-category="Check Digit & Validation">Modulo 43 (optional) |
| ITF-14 | Modulo 10 (weighted 3,1) |
| SSCC-18 | Modulo 10 (weighted 3,1) |
GTIN Validation
Beyond check digits, GTIN validation includes:
- Format check: Correct length (8, 12, 13, or 14 digits), numeric only
- Prefix validation: GS1 prefix exists and is assigned to an active member organization
- GEPIR lookup: Verify the GTIN is registered in the GS1 Global Electronic Party Information Registry
- Company prefix match: Confirm the prefix belongs to the company claiming to produce the product
GS1 Application Identifier Validation
For GS1-128 and Data Matrix with GS1 AIs for pharma and food traceability." data-category="2D & Matrix Symbologies">GS1 DataMatrix, validate each AI field:
- AI exists: The AI number is defined in the GS1 General Specifications
- Data format: The value matches the AI's format (numeric, alphanumeric, date)
- Length: Fixed-length AIs have exact lengths; variable-length AIs have maximums
- Date validity: Date AIs (11, 13, 15, 17) contain valid YYMMDD dates
- Separator placement: FNC1 separators appear after variable-length fields (not after fixed-length ones)
Business Rule Validation
Application-specific rules that go beyond format checking:
- Expiry date is in the future
- Batch number matches an existing production batch
- Serial number is unique within the GTIN scope
- Weight or measure is within expected range
- Product is not recalled or discontinued
Validation Pipeline Architecture
A robust validation system processes data in stages:
- Syntax check: Is it a valid barcode data string?
- Format check: Does it match the expected symbology format?
- Integrity check: Is the check digit correct?
- Structure check: Are AIs properly formatted with correct separators?
- Data check: Are individual field values valid?
- Business rules: Does the data meet application-specific requirements?
- Master data lookup: Does the GTIN/SSCC exist in your system?
Error Handling
When validation fails:
- Return specific error codes identifying which check failed
- Log the invalid data for analysis (common errors reveal systemic issues)
- Provide actionable error messages (e.g., "Check digit should be 7, got 3")
- In scanning applications, prompt for re-scan before rejecting outright
- Track validation failure rates by source to identify problematic printers or processes