Skip to content
Corex

Phone

Corex\Forms\Validation\Rules\Phone · class · Forms layer

A telephone number in E.164 shape (#148 item 4). Before this there was no phone validation at all, so a phone field could only be length-capped and 12345 and call me both passed — the team receives numbers it cannot dial. Formatting characters are stripped before the pattern runs. People write +20 101 699 9700, +44 (20) 7946-0958 and +1.555.0100, and a rule that rejects a correct number for its spaces teaches them the form is broken rather than that their number is. Only separators are removed; letters are not, so call me still fails. phone alone is international. E.164 has no leading zero, so 010 1699 9700 is refused: it cannot be dialled without knowing the country. phone:national accepts that form as well, for a form whose audience is local and whose team knows which country it is (#249). Empty is deferred to required, like every other rule here: a rule that also enforced presence would make an optional phone field impossible to express.

validate(mixed $value, array $params, array $allValues): ?string

Section titled “validate(mixed $value, array $params, array $allValues): ?string”