CIE IGCSE | 7.5.2 Format Checks and Check Digits

Lesson objective

Explain format checks and check digits, apply a given check-digit method and recognise which errors these checks may leave undetected.

Learn

7.5.2 | FORMAT CHECKS AND CHECK DIGITS

01 | THE RIGHT LENGTH IS NOT THE WHOLE STORY

A school identifier must contain two uppercase letters followed by four digits. AB1234 looks suitable. So does XY0042. But 1234AB has the same six-character length and still breaks the rule.

A format check checks whether data follows a specified pattern or structure. It examines which kinds of characters appear and where they appear.

The previous lesson’s length check counts characters. A format check can go further: exactly two letters first, then exactly four digits. A complete pattern rule often also implies a particular length.

Neither check proves that the identifier belongs to a real student. They test the representation, not every fact the code is meant to identify.

02 | DEFINE THE PATTERN BEFORE CHECKING IT

“Check the format” is incomplete unless the required format is known. For this example, the rule is: exactly six characters, positions 1 and 2 are uppercase English letters A to Z, and positions 3 to 6 are digits 0 to 9.

1

A

LETTER

2

B

LETTER

3

1

DIGIT

4

2

DIGIT

5

3

DIGIT

6

4

DIGIT

The zeros in XY0042 are part of the identifier’s text. It should not be converted into a quantity that loses those characters.

Make any permitted alternatives explicit. Our example rejects lowercase letters. A different system might accept them or convert them to uppercase before checking, but that would be a different specified rule.

A precise rule lets a programmer construct a check and a tester predict which entries should pass.

03 | APPLY THE SAME RULE TO DIFFERENT INPUTS

Follow the rule position by position. Check length first so that you do not try to inspect a character position that does not exist.

Our specified school-code pattern
InputFormat outcomeReason
AB1234PassTwo uppercase letters then four digits
XY0042PassLeading zeros allowed in the digit positions
1234ABFailWrong positions
ab1234FailLowercase not permitted by this rule
AB12C4FailLetter in a digit position
AB123FailWrong length

AB12C4 fails because position 5 contains a letter where a digit is required. AB123 fails because it is too short. A six-character code can fail even though every character belongs to one of the permitted categories overall: their positions also matter.

The code AB9999 passes the pattern rule. Whether it is a registered student code requires a separate lookup or other rule. Passing a format check does not establish that a code exists.

04 | PATTERN CHECKS HAVE CLEAR LIMITS

A date written as 31/02/2026 has the visible pattern two digits, slash, two digits, slash, four digits. That does not make it a real calendar date. February does not have thirty-one days.

A format check can test the arrangement, while additional checks establish valid calendar values and relationships. Similarly, an email-like string with a permitted structure does not prove that a mailbox exists or that a message can be delivered.

A typed code might follow the right pattern but identify the wrong person. An entered date might be valid yet be the wrong date for the event.

Keep the claim precise: a format check establishes conformance to the pattern it tests. It does not establish all possible validity rules or factual accuracy.

05 | HOW TO DESIGN A FORMAT CHECK

For the school code, break the check into manageable decisions: is the length six, are the first two characters allowed letters, and are the last four allowed digits?

Once a required condition fails, the code can be rejected with a useful message. If every required condition succeeds, it passes this format rule.

You can describe those decisions precisely without inventing a Cambridge keyword called FORMATCHECK. A real implementation might inspect characters individually or use a pattern-matching facility supplied by its programming language.

In this lesson, the format design is expressed as stated tests rather than a claim that an undefined helper routine will run. When given specific pseudocode tools in a question, use those tools and keep the conditions explicit.

Useful tests include the correct pattern, too few characters, too many characters, a misplaced letter, a misplaced digit and any required case rule.

06 | WHAT IS A CHECK DIGIT?

A check digit is an additional digit calculated from the other digits in a code using an agreed method. It is included so that a later check can detect certain entry or copying errors.

The receiving system checks whether the data digits and the supplied check digit still satisfy that method. If they do not, it rejects the code or flags a possible error.

Check digits are used with identifiers such as product codes and ISBNs. Different systems use different calculations. Use the method supplied in the question rather than assuming one universal rule.

A check digit is not encryption, a secret password or automatic error correction. It adds a consistency test. A failed result does not ordinarily tell the system which digit was intended.

07 | A WORKED METHOD WITH WEIGHTS

We will use an illustrative classroom method, not a claim about the exact algorithm of a particular barcode or ISBN standard.

The payload has four digits. From left to right, multiply them by weights 1, 3, 1 and 3. Add the products. Choose a check digit that makes the combined total a multiple of ten.

A weight is the multiplier assigned to a position. The payload is the original data portion, before the extra check digit is added.

Illustrative weights 1, 3, 1, 3
Payload positionDigitWeightProduct
1414
28324
3212
46318
Weighted sum48

For payload 4826, the weighted sum is 48. The next multiple of ten is 50, so the check digit is 2. The complete code is 48262: four payload digits followed by the check digit.

The rightmost 2 is the added check digit. It is not another payload digit to multiply by the next payload weight in this particular method.

08 | VERIFY THE COMPLETE CODE

When code 48262 is entered, separate the four payload digits 4826 from the supplied check digit 2. Recalculate the weighted payload sum, 48, and add the check digit.

The combined total is 50, which is divisible by ten. The code passes this check-digit rule.

MOD produces the remainder after integer division. Fifty MOD ten is zero, so the condition (WeightedSum + CheckDigit) MOD 10 = 0 tests consistency for this method.

If the user instead enters 48362, the payload sum is 4 + 24 + 3 + 18 = 49. Adding the supplied digit 2 gives 51. Its remainder on division by ten is 1, so the code fails.

The system detects an inconsistency. It has not proved whether the error was the third payload digit, the check digit or some other part.

09 | CALCULATE THE DIGIT WITHOUT A SPECIAL CASE

For an integer weighted sum, calculate the check digit as:

CheckDigit ← (10 - (WeightedSum MOD 10)) MOD 10

If WeightedSum is 48, its remainder is 8. Ten minus eight is two, and two MOD ten is two.

If WeightedSum is already 50, its remainder is zero. The final MOD converts ten back to zero, giving check digit 0 rather than an invalid extra digit 10.

For payload 1234, the weighted sum is 1 + 6 + 3 + 12 = 22. The check digit is 8, so 12348 passes because 22 + 8 = 30.

This formula follows our stated method. A different method may use different weights, modulus or rules for its final character.

10 | READ A CHECKING ALGORITHM

The pseudocode below assumes the four payload digits have already been separated into an array, each integer from 0 to 9. CheckDigit is also an integer from 0 to 9. The preparation and digit checks must be performed by the surrounding input routine.

DECLARE Payload : ARRAY[1:4] OF INTEGER
DECLARE CheckDigit : INTEGER
DECLARE WeightedSum : INTEGER
// Assume Payload and CheckDigit are already supplied and checked
// Every element and CheckDigit is an integer from 0 to 9
WeightedSum ← Payload[1] + 3 * Payload[2] + Payload[3] + 3 * Payload[4]
IF (WeightedSum + CheckDigit) MOD 10 = 0
  THEN
    OUTPUT "Check-digit rule satisfied"
  ELSE
    OUTPUT "Check-digit rule failed: check the entry"
ENDIF

The algorithm calculates the weighted sum, adds the supplied check digit and tests the remainder. It does not perform a complete format check on arbitrary raw text.

For code 48262, Payload contains 4, 8, 2 and 6, and CheckDigit contains 2. For code 48362, the third payload element is 3 instead.

This separation keeps responsibilities clear: one part checks and interprets the input representation; another performs the agreed arithmetic check.

11 | SOME TRANSPOSITIONS ARE DETECTED, SOME ARE NOT

A transposition error swaps the positions of characters. Weights can make many such changes affect the sum, but they do not guarantee detection of every possible swap.

If 48262 is changed to 84262 by swapping the first two payload digits, the new weighted sum is 8 + 12 + 2 + 18 = 40. Adding the unchanged check digit 2 gives 42, so the code fails.

Now consider payload 0526. Its weighted sum is 0 + 15 + 2 + 18 = 35, giving check digit 5 and complete code 05265.

Swap the first two digits to obtain 50265. The new weighted sum is 5 + 0 + 2 + 18 = 25. Adding the same check digit 5 gives 30, so this different code still passes.

This counterexample is important: the method detects some errors, not all. Do not claim a check digit makes incorrect entry impossible.

12 | A VALID CODE CAN STILL BE THE WRONG CODE

Someone could copy a different complete valid code, including its check digit. It may pass format and arithmetic checks while identifying the wrong item.

Multiple altered digits can also compensate so that the consistency condition remains satisfied. Detection depends on the actual method and the particular changes.

A failed check indicates that the entered digits do not satisfy the rule. The usual response is to reject the entry and request a correction or re-entry, not to guess which digit should change.

Additional measures, such as comparison with a source or checking that the identifier exists in records, address different concerns. A check digit does not replace every other check.

13 | COMBINE CHECKS IN A SENSIBLE ORDER

For our five-digit example code, first require a supplied value. Then check that it contains exactly five digit characters, preserving leading zeros as text.

Only after that preparation should the program separate and interpret the digits for the arithmetic check. Trying to multiply a letter or read a missing character would not be a useful validation response.

The checks establish different properties
Entered textRepresentationArithmetic outcome
48262Five digit charactersPass: combined sum 50
48362Five digit charactersFail: combined sum 51
48A62Wrong character patternDo not attempt the numeric check
4826Wrong lengthDo not attempt the five-digit check
50265Five digit charactersPass despite the illustrated transposition

The exact five-digit numeric pattern checks representation. The weighted calculation checks consistency. A separate record lookup might check whether the identifier is recognised.

Each result has a limited meaning. Together the checks reduce some entry problems, but they still cannot guarantee the user chose the intended valid item.

14 | PRACTISE THE CALCULATION AND EXPLAIN ITS PURPOSE

For payload 2468, the weighted sum is 2 + 12 + 6 + 24 = 44, so check digit 6 gives complete code 24686. For payload 0000, the sum is zero and the check digit is zero.

For a describe question, explain the calculation and later comparison. For an explain question, connect the extra digit to detection: “An entered code is checked using the same agreed rule, so many digit changes produce an inconsistent result and are flagged.”

Compare the two main checks precisely: a format check tests the required character pattern; a check-digit calculation tests an arithmetic relationship between digits.

You should now be able to apply a supplied method, preserve the distinction between payload and check digit, and explain both detection and its limits.

MATCH THE CHECKING TERM

Terminology

Terminology

Format check

Checking whether data conforms to a specified character pattern or structure.

Pattern

The specified arrangement of permitted characters.

Length check

Checking character count; it does not by itself check character positions.

Check digit

An additional digit calculated from other digits using an agreed method to help detect entry or copying errors.

Payload

The original data portion before the check digit is added.

Weight

A multiplier assigned to a position in a check-digit calculation.

Weighted sum

The total of the products of digits and their assigned weights.

MOD

The remainder after integer division.

Multiple of ten

An integer divisible by ten with remainder zero.

Recalculation

Applying the agreed method again to entered digits.

Consistency check

Checking whether data satisfies a specified relationship.

Transposition error

An error that swaps characters’ positions.

Leading zero

A zero at the start of an identifier that may need preservation as text.

Validation

Checking data against stated acceptability rules.

Accuracy

Whether data correctly represents the intended fact or identifier.

Error detection

Identifying an inconsistency without necessarily locating or correcting the erroneous digit.

Re-entry

Supplying the input again after a failed check.

False acceptance

An erroneous value satisfying the checks despite being wrong for the intended use.

Questions

Questions

CHECK YOUR UNDERSTANDING

Select all correct choices. Each exact set earns one point.

1. Which satisfy two uppercase letters followed by four digits?
2. Which can a pattern-only date check establish?
3. For payload 4826 and weights 1,3,1,3, what is the weighted sum?
4. Which check digit completes that payload under our method?
5. Why does 48362 fail?
6. Which statements about check digits are correct?
7. Which are correct for the illustrated transposition 05265 to 50265?
8. Which should occur before our arithmetic check on raw text?

EXPLAIN AND COMPARE

Write your answers before revealing each sample.

1. Compare length and format checks using the school-code example.

2. Explain why passing a format check does not prove an identifier exists.

3. Describe how a check digit is used.

4. Calculate the check digit for payload 2468 using weights one, three, one, three and a multiple-of-ten total.

5. Explain why the final MOD ten is used in the digit-generation formula.

6. Explain why the illustrated method does not detect every transposition.

7. Explain why a failed check should not automatically be corrected by guessing a digit.

8. Suggest checks for our five-digit complete code and their order.

CALCULATE AND INVESTIGATE | APPLY THE GIVEN METHOD

Using weights 1, 3, 1 and 3, generate the check digit for payloads 1234, 2468 and 0000. Then check complete code 24786. State what a failed result tells you and what it does not tell you.

Reveal worked answers

1234 has sum 22 and check digit 8: code 12348. 2468 has sum 44 and check digit 6: code 24686. 0000 has sum 0 and check digit 0: code 00000. For 24786 the payload sum is 2 + 12 + 7 + 24 = 45; adding 6 gives 51, so it fails. The failure shows the entered code is inconsistent with the rule, but does not identify the exact intended code or error position.

Flashcards

Flashcards

Click to flip. Select the ideas you need to revisit.

0 cards selected for revision.

    Selections are kept while this page is open.

    Workbook

    Workbook

    COMING SOON

    The workbook for 7.5.2 Format Checks and Check Digits is coming soon. Complete the matching task and written questions in your exercise book.