Skip to main content

Module validation

Module validation 

Source
Expand description

Format validators for the email / phone field types.

These back the #[rustio(format = "email" | "phone")] field attribute the scaffolder emits: at rest both columns are plain TEXT, so the only thing that distinguishes them from a str field is the widget (<input type="email"> / "tel") and the check applied in the derived from_form.

The checks are deliberately structural, not exhaustive — full RFC 5322 e-mail and E.164 phone validation are rabbit holes that reject legitimate values. The goal is to catch obvious typos (alice instead of alice@example.com, call me instead of a number), not to be a spec-complete parser. Projects that need stricter rules override from_form or add a ModelAdmin validation hook.

Functions§

is_valid_email
true when s looks like an e-mail address: a non-empty local part, a single @, and a domain that contains a dot and doesn’t start or end with one. Whitespace is rejected. This is a typo guard, not RFC 5322.
is_valid_phone
true when s looks like a phone number: between 7 and 15 digits (the E.164 ceiling), with only digits and the common separators + - ( ) space . in between. This is a typo guard, not E.164.