Struct PhoneNumber
Represents a validated E.164 phone number. The number must be 7-15 digits, containing only numeric characters.
public readonly struct PhoneNumber
- Inherited Members
Remarks
E.164 is the international telephone numbering plan that ensures each device has a globally unique number.
Use Parse(string) to create an instance with validation. The international indicator (+) is optional and will be stripped during parsing.
See E.164 on Wikipedia for more information.
Properties
Number
Gets the phone number without international indicator.
public string Number { get; }
Property Value
NumberWithInternationalIndicator
Gets the phone number with international indicator.
public string NumberWithInternationalIndicator { get; }
Property Value
Methods
Parse(string)
Parses and validates a phone number according to E.164 specifications.
public static Result<PhoneNumber> Parse(string number)
Parameters
numberstringThe phone number to validate. May include the international indicator (+). Must be 7-15 digits after removing the indicator.
Returns
- Result<PhoneNumber>
A Result<T> containing the validated PhoneNumber on success, or an IResultFailure describing the validation error on failure.
Examples
var result = PhoneNumber.Parse("+14155552671");
result.Match(
phone => Console.WriteLine($"Number: {phone.NumberWithInternationalIndicator}"),
failure => Console.WriteLine($"Invalid: {failure.GetFailureMessage()}")
);
ToString()
public override string ToString()