This question evaluates a candidate's practical front-end development skills, including DOM manipulation, client-side input validation and pattern matching, edge-case handling, accessibility awareness, and basic testing and telemetry considerations.
Context: Implement this in a vanilla HTML/CSS/JavaScript environment (single file, no frameworks). You are given a mapping from country names to passport number patterns, for example:
validate(country, value)
that returns
true
only if
value
exactly matches the selected country’s pattern; otherwise returns
false
. Specify how to handle edge cases: empty input, leading/trailing whitespace, unexpected country key, case handling, extra/invalid characters, and partial matches.
Login required