PhoneNumberFieldState

State for a phone number field: the selected country, the digits typed, and everything derived from them.

The digits are the single source of truth. The formatted text shown in the field is derived from them, never stored independently, which is what keeps the display and the E.164 output from drifting apart — the failure mode where a field reads +254 712 345 678 and submits 254712345678 .

Properties

Link copied to clipboard

Line types accepted, or empty for any. Restricting this to PhoneNumberType.SmsCapable makes the field reject a landline that is otherwise perfectly valid — which is what an SMS code flow needs, and what plain validity cannot express.

Link copied to clipboard

The selected country. Drives parsing, formatting and validation.

Link copied to clipboard

True once the user has left the field or attempted submission.

Link copied to clipboard

Raw digits, no separators.

Link copied to clipboard

The field's text and cursor.

Link copied to clipboard

The complete evaluated value: formatted forms, E.164, validity.

Functions

Link copied to clipboard
fun clear()

Clears the number. Leaves the country alone — the user did not un-choose it.

Link copied to clipboard

Marks the field touched, so validation messages become visible.

Link copied to clipboard

Applies a text edit from the field.

Link copied to clipboard
fun selectCountry(newCountry: Country)

Changes the country, keeping the digits the user already typed.

Link copied to clipboard
fun setFullNumber(raw: String, allowCountryChange: Boolean = true)

Parses a full or partial number, adopting the country it identifies when allowCountryChange.