← Questions

Passport number form with per-country formats

0
StripeCodingLast asked Aug 2025

A coding interview question asked in Stripe's technical phone screen, last asked Aug 2025. It tests frontend, forms and validation.

You get a map from country to passport number format, for example {USA: "LLDDDD", Canada: "AALLDDDD"}. In a format, L is a letter (A to Z, either case), D is a digit and A is a letter or a digit. Build a small form that checks a passport number against the selected country's format.

What to build

  1. Layout: a country selector filled from the map's keys, a passport number input and a Validate button.
  2. Validation: validate(country, value) -> boolean returns true only if the whole value matches the country's format, character by character.
  3. Wiring: clicking Validate shows an inline error when the number is invalid. Changing the input clears the error; changing the country clears both the input and the error.
  4. Tests: tests in the console that cover valid and invalid numbers for several countries and the edge cases.

Example

validate("USA", "AB1234")       ->  true
validate("USA", "ab1234")       ->  true     # letters in either case
validate("USA", "AB123")        ->  false    # too short
validate("USA", "AB12345")      ->  false    # a prefix match is not enough
validate("Canada", "9XAB1234")  ->  true     # A, A, L, L, D, D, D, D
validate("Germany", "C01X00T47") ->  false   # unknown country

Clarifying questions

  • Should leading and trailing spaces be trimmed or rejected?
  • Is an unknown country an error to show or just false?
  • Should the input show hints or format as the user types?
  • Which frameworks may I use?

What a strong answer covers

  • A validator that compares lengths first, then each character against its format symbol, with no regex built from raw input (or a regex built safely from the format).
  • Clear rules for empty input, whitespace, case and unknown countries.
  • Accessible markup: a label for every control, the error tied to the input with aria-describedby and announced, focus kept on the input.
  • Tests for each symbol type, wrong lengths, mixed case and switching countries.

Follow-ups

  • How would you make this ready for production: accessibility review, translated messages, keyboard support, analytics on failed attempts?
  • Countries now allow several formats each.
  • Show the expected format as a placeholder and format the input as the user types.

Where it's asked

  • Stripe · Technical phone screen · Last asked Aug 202560 min · One realistic task in parts, in a project editor (CoderPad project mode or HackerRank Projects) with several files and tests

What it tests

frontend · forms · validation

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding