Table of Contents

Class PhoneNumberAttribute

Namespace
PhoneNumbers.Extensions
Assembly
PhoneNumbers.Extensions.dll

Validates that a property, field, or parameter is a valid phone number, using the same validity check as IsValidNumber(PhoneNumber) rather than a loose format regex. Accepts a string (parsed via Region) or an already-parsed PhoneNumber.

public sealed class PhoneNumberAttribute : ValidationAttribute
Inheritance
PhoneNumberAttribute
Inherited Members

Constructors

PhoneNumberAttribute()

public PhoneNumberAttribute()

Properties

Region

Default region used to interpret a national-format string, e.g. "US". Not needed for numbers already in E.164 format (leading "+"), or when the value is a PhoneNumber.

public string Region { get; set; }

Property Value

string

Methods

IsValid(object)

Determines whether the specified value of the object is valid.

public override bool IsValid(object value)

Parameters

value object

The value of the object to validate.

Returns

bool

true if the specified value is valid; otherwise, false.

Exceptions

InvalidOperationException

The current attribute is malformed.

NotImplementedException

Neither overload of IsValid has been implemented by a derived class.