Secure Exchanges SDK Documentation
Search Results for

    Show / Hide Table of Contents

    Class PhoneHelper

    The PhoneHelper class provides utility methods for validating, normalizing, and manipulating phone numbers. It includes methods for:

    • Validating phone numbers against regular expressions and using the PhoneNumberUtil library.
    • Checking if phone numbers can receive SMS messages.
    • Normalizing phone numbers by removing common formatting characters.
    • Adding a country code to national phone numbers if not already present.

    This class aims to ensure that phone numbers are in a consistent and valid format before performing operations on them.

    Inheritance
    object
    PhoneHelper
    Inherited Members
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    Namespace: SecureExchangesSDK.Helpers
    Assembly: SecureExchangesSDK.dll
    Syntax
    public static class PhoneHelper

    Methods

    AddCountryCodeToNationalNumber(string, string)

    Adds the country code to a national phone number if not already present.

    Declaration
    public static string AddCountryCodeToNationalNumber(string phoneNumber, string countryCode)
    Parameters
    Type Name Description
    string phoneNumber

    The national phone number.

    string countryCode

    The country code to add.

    Returns
    Type Description
    string

    The phone number with the country code added, or the original phone number if an error occurs.

    IsValidPhoneNumber(string, params int[])

    Validates the format of a phone number using regular expressions and checks its validity using the PhoneNumberUtil library. The method also checks if the input string is null or empty, returning false if it is. If no number types are specified, it defaults to validating mobile, fixed-line or mobile, and fixed-line phone numbers.

    Declaration
    public static bool IsValidPhoneNumber(string phoneNumber, params int[] numberTypes)
    Parameters
    Type Name Description
    string phoneNumber

    The phone number to validate.

    int[] numberTypes

    Optional parameter to specify acceptable phone number types as int values. Defaults to mobile, fixed-line or mobile, and fixed-line phone numbers if not specified. Acceptable int values: 0 - FIXED_LINE 1 - MOBILE 2 - FIXED_LINE_OR_MOBILE 3 - TOLL_FREE 4 - PREMIUM_RATE 5 - SHARED_COST 6 - VOIP 7 - PERSONAL_NUMBER 8 - PAGER 9 - UAN 10 - VOICEMAIL 11 - UNKNOWN

    Returns
    Type Description
    bool

    True if the phone number is not null/empty and is valid according to the regular expressions and PhoneNumberUtil, false otherwise.

    IsValidPhoneNumberAndCanReceiveSMS(string, string)

    Checks if a phone number can receive SMS messages. The method first checks if the input is not null or empty. It then parses the phone number and checks its type, and validates the phone number's format and overall validity.

    Declaration
    public static bool IsValidPhoneNumberAndCanReceiveSMS(string phoneNumber, string countryCode = null)
    Parameters
    Type Name Description
    string phoneNumber

    The phone number to check.

    string countryCode

    The country code to add if the phone number is national.

    Returns
    Type Description
    bool

    True if the phone number is not null/empty, is valid, and can receive SMS messages, false otherwise.

    NormalizePhone(string)

    Normalizes a phone number by removing spaces, dashes, and parentheses.

    Declaration
    public static string NormalizePhone(string phoneNumber)
    Parameters
    Type Name Description
    string phoneNumber

    The phone number to normalize.

    Returns
    Type Description
    string

    The normalized phone number.

    ValidatePhoneNumber(string, string, string, out string)

    Validates the phone number format for a specific region and country code.

    Declaration
    [Obsolete("This method is obsolete. Use IsValidPhoneNumber instead.")]
    public static bool ValidatePhoneNumber(string region, string countryCode, string phoneNumber, out string finalPhoneNumber)
    Parameters
    Type Name Description
    string region

    The region code.

    string countryCode

    The country code.

    string phoneNumber

    The phone number to validate.

    string finalPhoneNumber

    The validated phone number with the country code added.

    Returns
    Type Description
    bool

    True if the phone number is valid for the specified region and country code, False otherwise.

    In this article
    Back to top Secure Exchanges Inc. - Documentation