Skip to content

How Telixon works

Google libphonenumber’s metadata is compiled ahead of time into a single deterministic finite automaton (DFA), stored as binary tables. Every answer about a phone number is read from those tables.

Parsing is a walk over the automaton, one digit per step. The state the walk ends on determines the region, the number type, and whether the number is valid.

const number = parsePhoneNumber('+1 (415) 555-0132');
// the walk has already happened
number.getRegion(); // 'US'
number.getNumberType(); // 'FIXED_LINE_OR_MOBILE'
number.isValid(); // true

A number is valid when the walk ends on an accepting state. Everything else is a classified failure, returned as a typed value:

parsePhoneNumber('5550132', { defaultRegion: 'US' }).getValidationError();
// { kind: 'POSSIBLE_LOCAL_ONLY' }

Seven digits form a US number that can be dialed only inside its own area code. The walk ends on a state that records exactly that. The nine variants are in ValidationError.

parsePhoneNumber walks the automaton over the whole string. An input controller walks it again on every keystroke, over the value as it stands. It is the same walk, which makes their answers agree by construction. A controller can hand you a PhoneNumber at any moment, mid-typing.

const controller = createInternationalInputController();
controller.setValue('+1 (415) 555-0132');
controller.getPhoneNumber().formatE164(); // '+14155550132'
parsePhoneNumber('+1 (415) 555-0132').formatE164(); // '+14155550132'