PhoneNumberValue

data class PhoneNumberValue(val country: Country, val nationalNumber: String, val formattedNationalNumber: String, val internationalNumber: String, val e164Number: String?, val isPossible: Boolean, val isValid: Boolean, val validity: PhoneNumberValidity = PhoneNumberValidity.Empty, val numberType: PhoneNumberType? = null)(source)

Everything a caller needs to know about the phone number currently in the field.

The point of this type is that callers never build an E.164 string themselves. Concatenating dialCode + digits is wrong for any country with a national trunk prefix (a UK mobile typed as 07400 123456 is +447400123456, not +4407400123456), so e164Number is produced by libphonenumber and is null — deliberately, not empty-string — whenever the number is not yet parseable.

Constructors

Link copied to clipboard
constructor(country: Country, nationalNumber: String, formattedNationalNumber: String, internationalNumber: String, e164Number: String?, isPossible: Boolean, isValid: Boolean, validity: PhoneNumberValidity = PhoneNumberValidity.Empty, numberType: PhoneNumberType? = null)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

The selected country. Determines the region used for parsing and formatting.

Link copied to clipboard

Storage/API form (e.g. "+254712345678"), or null when the number cannot be parsed. Never treat null as "no number" — check nationalNumber for that.

Link copied to clipboard

The same digits grouped for display (e.g. "0712 345 678").

Link copied to clipboard

Human-readable international form (e.g. "+254 712 345 678"). Falls back to the raw input when parsing fails, so it is always safe to display.

Link copied to clipboard

True when the user has not typed anything.

Link copied to clipboard

libphonenumber considers the length plausible for the region. True before isValid becomes true, which makes it the right signal for "keep typing" affordances.

Link copied to clipboard

libphonenumber considers this a real, dialable number for the region. This is the only flag that should gate submission or verification.

Link copied to clipboard

Digits the user typed, with formatting stripped (e.g. "712345678").

Link copied to clipboard

What kind of line this is, or null when nothing has been typed yet or the number could not be parsed. Note that many regions report PhoneNumberType.FixedLineOrMobile for every valid number — compare with PhoneNumberType.satisfies rather than by equality.

Link copied to clipboard

The granular reason behind isValid, for precise error messaging.

Functions

Link copied to clipboard

Projects a PhoneNumberValue into the legacy Phone snapshot.