← Questions
Passport number form with per-country formats
0
I was asked this
No reports yet. Sign in to say where you were asked it.
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
- Layout: a country selector filled from the map's keys, a passport number input and a Validate button.
-
Validation:
validate(country, value) -> booleanreturnstrueonly if the whole value matches the country's format, character by character. - 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.
- 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-describedbyand 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
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
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
