Table of Contents

Class CountryRuleExtensions

Namespace
HeroKit.Globalization
Assembly
HeroKit.dll

Validates and formats country-specific values with the rules of a Country.

public static class CountryRuleExtensions
Inheritance
CountryRuleExtensions
Inherited Members

Remarks

All methods throw NotSupportedException when the country has no rules for the value type.

Methods

FormatPhone(string?, Country)

Formats a phone number in the national notation of a country.

public static string? FormatPhone(this string? value, Country country)

Parameters

value string

The phone number in any common notation.

country Country

The country.

Returns

string

The formatted number, for example "0532 123 45 67", or null if the value is not valid.

FormatVehiclePlate(string?, Country)

Formats a vehicle plate in the national notation of a country.

public static string? FormatVehiclePlate(this string? value, Country country)

Parameters

value string

The plate in any common notation.

country Country

The country.

Returns

string

The formatted plate, for example "34 ABC 123", or null if the value is not valid.

IsValidMobilePhone(string?, Country)

Checks whether a value is a valid mobile phone number of a country.

public static bool IsValidMobilePhone(this string? value, Country country)

Parameters

value string

The phone number in any common notation.

country Country

The country.

Returns

bool

True if valid and mobile; otherwise false.

IsValidNationalId(string?, Country)

Checks whether a value is a valid national identity number of a country, for example a TCKN for Türkiye.

public static bool IsValidNationalId(this string? value, Country country)

Parameters

value string

The identity number.

country Country

The country.

Returns

bool

True if valid; otherwise false.

IsValidPhone(string?, Country)

Checks whether a value is a valid phone number of a country.

public static bool IsValidPhone(this string? value, Country country)

Parameters

value string

The phone number in any common notation.

country Country

The country, for example Turkey.

Returns

bool

True if valid; otherwise false.

Examples

"0532 123 45 67".IsValidPhone(Countries.Turkey); // true

IsValidPostalCode(string?, Country)

Checks whether a value is a valid postal code of a country.

public static bool IsValidPostalCode(this string? value, Country country)

Parameters

value string

The postal code.

country Country

The country.

Returns

bool

True if valid; otherwise false.

IsValidTaxId(string?, Country)

Checks whether a value is a valid tax identifier of a country, for example a VKN or TCKN for Türkiye.

public static bool IsValidTaxId(this string? value, Country country)

Parameters

value string

The tax identifier.

country Country

The country.

Returns

bool

True if valid; otherwise false.

IsValidVehiclePlate(string?, Country)

Checks whether a value is a valid vehicle plate of a country.

public static bool IsValidVehiclePlate(this string? value, Country country)

Parameters

value string

The plate in any common notation.

country Country

The country.

Returns

bool

True if valid; otherwise false.

ToE164(string?, Country)

Converts a phone number of a country to E.164.

public static string? ToE164(this string? value, Country country)

Parameters

value string

The phone number in any common notation.

country Country

The country.

Returns

string

The E.164 form, for example "+905321234567", or null if the value is not valid.