Regular languages and the machine that recognises them
Start with the simplest useful class of formats: those describable by a regular expression. Phone numbers, dates, identifiers, enumerations, numeric literals, and a surprising share of the fields inside a JSON schema.
Every regular expression can be converted mechanically into a finite state machine. The construction is standard: the expression becomes a nondeterministic automaton, which is then converted to a deterministic one by the subset construction, and optionally minimised.
A deterministic finite automaton has a set of states, one start state, a set of accepting states, and a transition function taking a state and a character to exactly one next state.
The property that matters for us is determinism. From a given state, reading a given character leads to exactly one place. There is no search, no backtracking, and no ambiguity about where you are.
That is what turns validation into something cheap. The automaton's current state is a complete summary of everything the prefix so far implies about what may come next.

