Documentation
¶
Overview ¶
Package phonenumbers is a no-external-runtime-dependencies fork foundation for github.com/nyaruka/phonenumbers/v2.
The fork has plain Go model structs and compact custom binary metadata. Its intended completed scope is parsing, validating, and formatting international phone numbers while tracking Google's libphonenumber metadata and Java reference behavior through nyaruka parity.
Port of java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java.
Index ¶
- Constants
- Variables
- func CanBeInternationallyDialled(number *PhoneNumber) bool
- func ConvertAlphaCharactersInNumber(number string) string
- func Format(number *PhoneNumber, numberFormat PhoneNumberFormat) string
- func FormatByPattern(number *PhoneNumber, numberFormat PhoneNumberFormat, ...) string
- func FormatInOriginalFormat(number *PhoneNumber, regionCallingFrom string) string
- func FormatNationalNumberWithCarrierCode(number *PhoneNumber, carrierCode string) string
- func FormatNationalNumberWithPreferredCarrierCode(number *PhoneNumber, fallbackCarrierCode string) string
- func FormatNumberForMobileDialing(number *PhoneNumber, regionCallingFrom string, withFormatting bool) string
- func FormatOutOfCountryCallingNumber(number *PhoneNumber, regionCallingFrom string) string
- func FormatOutOfCountryKeepingAlphaChars(number *PhoneNumber, regionCallingFrom string) string
- func GetCountryCodeForRegion(regionCode string) int
- func GetCountryMobileToken(countryCallingCode int) string
- func GetLengthOfGeographicalAreaCode(number *PhoneNumber) int
- func GetLengthOfNationalDestinationCode(number *PhoneNumber) int
- func GetNationalSignificantNumber(number *PhoneNumber) string
- func GetNddPrefixForRegion(regionCode string, stripNonDigits bool) string
- func GetRegionCodeForCountryCode(countryCallingCode int) string
- func GetRegionCodeForNumber(number *PhoneNumber) string
- func GetRegionCodesForCountryCode(countryCallingCode int) []string
- func GetSupportedCallingCodes() map[int]bool
- func GetSupportedGlobalNetworkCallingCodes() map[int]bool
- func GetSupportedRegions() map[string]bool
- func GetSupportedTypesForNonGeoEntity(countryCallingCode int) map[PhoneNumberType]bool
- func GetSupportedTypesForRegion(regionCode string) map[PhoneNumberType]bool
- func IsAlphaNumber(number string) bool
- func IsMobileNumberPortableRegion(regionCode string) bool
- func IsNANPACountry(regionCode string) bool
- func IsNumberGeographical(phoneNumber *PhoneNumber) bool
- func IsNumberGeographicalForType(phoneNumberType PhoneNumberType, countryCallingCode int) bool
- func IsPossibleNumber(number *PhoneNumber) bool
- func IsPossibleNumberForType(number *PhoneNumber, numberType PhoneNumberType) bool
- func IsPossibleNumberFromRegion(number string, regionDialingFrom string) bool
- func IsValidNumber(number *PhoneNumber) bool
- func IsValidNumberForRegion(number *PhoneNumber, regionCode string) bool
- func NormalizeDiallableCharsOnly(number string) string
- func NormalizeDigitsOnly(number string) string
- func ParseAndKeepRawInputToNumber(numberToParse, defaultRegion string, phoneNumber *PhoneNumber) error
- func ParseToNumber(numberToParse, defaultRegion string, phoneNumber *PhoneNumber) error
- func TruncateTooLongNumber(number *PhoneNumber) bool
- type MatchType
- type NumberFormat
- type PhoneMetadata
- type PhoneMetadataCollection
- type PhoneNumber
- func GetExampleNumber(regionCode string) *PhoneNumber
- func GetExampleNumberForNonGeoEntity(countryCallingCode int) *PhoneNumber
- func GetExampleNumberForType(typ PhoneNumberType) *PhoneNumber
- func GetExampleNumberForTypeInRegion(regionCode string, typ PhoneNumberType) *PhoneNumber
- func GetInvalidExampleNumber(regionCode string) *PhoneNumber
- func Parse(numberToParse, defaultRegion string) (*PhoneNumber, error)
- func ParseAndKeepRawInput(numberToParse, defaultRegion string) (*PhoneNumber, error)
- func (x *PhoneNumber) GetCountryCode() int32
- func (x *PhoneNumber) GetCountryCodeSource() PhoneNumber_CountryCodeSource
- func (x *PhoneNumber) GetExtension() string
- func (x *PhoneNumber) GetItalianLeadingZero() bool
- func (x *PhoneNumber) GetNationalNumber() uint64
- func (x *PhoneNumber) GetNumberOfLeadingZeros() int32
- func (x *PhoneNumber) GetPreferredDomesticCarrierCode() string
- func (x *PhoneNumber) GetRawInput() string
- type PhoneNumberDesc
- type PhoneNumberFormat
- type PhoneNumberType
- type PhoneNumber_CountryCodeSource
- type ValidationResult
Constants ¶
const Default_PhoneNumber_NumberOfLeadingZeros = int32(1)
Variables ¶
var ( ErrInvalidCountryCode = errors.New("invalid country code") ErrNotANumber = errors.New("the phone number supplied is not a number") ErrTooShortAfterIDD = errors.New("phone number had an IDD, but after this was not long enough to be a viable phone number") ErrTooShortNSN = errors.New("the string supplied is too short to be a phone number") ErrNumTooLong = errors.New("the string supplied is too long to be a phone number") )
var (
REGION_CODE_FOR_NON_GEO_ENTITY = "001"
)
Functions ¶
func CanBeInternationallyDialled ¶
func CanBeInternationallyDialled(number *PhoneNumber) bool
Returns true if the number can be dialled from outside the region, or unknown. If the number can only be dialled from within the region, returns false. Does not check the number is a valid number. Note that, at the moment, this method does not handle short numbers (which are currently all presumed to not be diallable from outside their country).
func ConvertAlphaCharactersInNumber ¶
Converts all alpha characters in a number to their respective digits on a keypad, but retains existing formatting.
func Format ¶
func Format(number *PhoneNumber, numberFormat PhoneNumberFormat) string
Formats a phone number in the specified format using default rules. Note that this does not promise to produce a phone number that the user can dial from where they are - although we do format in either 'national' or 'international' format depending on what the client asks for, we do not currently support a more abbreviated format, such as for users in the same "area" who could potentially dial the number without area code. Note that if the phone number has a country calling code of 0 or an otherwise invalid country calling code, we cannot work out which formatting rules to apply so we return the national significant number with no formatting applied.
func FormatByPattern ¶
func FormatByPattern(number *PhoneNumber, numberFormat PhoneNumberFormat, userDefinedFormats []*NumberFormat) string
FormatByPattern formats a phone number in the specified format using client-defined formatting rules. Note that if the phone number has a country calling code of zero or an otherwise invalid country calling code, we cannot work out things like whether there should be a national prefix applied, or how to format extensions, so we return the national significant number with no formatting applied.
func FormatInOriginalFormat ¶
func FormatInOriginalFormat(number *PhoneNumber, regionCallingFrom string) string
Formats a phone number using the original phone number format that the number is parsed from. The original format is embedded in the country_code_source field of the PhoneNumber object passed in. If such information is missing, the number will be formatted into the NATIONAL format by default. When the number contains a leading zero and this is unexpected for this country, or we don't have a formatting pattern for the number, the method returns the raw input when it is available.
Note this method guarantees no digit will be inserted, removed or modified as a result of formatting.
func FormatNationalNumberWithCarrierCode ¶
func FormatNationalNumberWithCarrierCode(number *PhoneNumber, carrierCode string) string
Formats a phone number in national format for dialing using the carrier as specified in the carrierCode. The carrierCode will always be used regardless of whether the phone number already has a preferred domestic carrier code stored. If carrierCode contains an empty string, returns the number in national format without any carrier code.
func FormatNationalNumberWithPreferredCarrierCode ¶
func FormatNationalNumberWithPreferredCarrierCode( number *PhoneNumber, fallbackCarrierCode string) string
Formats a phone number in national format for dialing using the carrier as specified in the preferredDomesticCarrierCode field of the PhoneNumber object passed in. If that is missing, use the fallbackCarrierCode passed in instead. If there is no preferredDomesticCarrierCode, and the fallbackCarrierCode contains an empty string, return the number in national format without any carrier code.
Use formatNationalNumberWithCarrierCode instead if the carrier code passed in should take precedence over the number's preferredDomesticCarrierCode when formatting.
func FormatNumberForMobileDialing ¶
func FormatNumberForMobileDialing( number *PhoneNumber, regionCallingFrom string, withFormatting bool) string
Returns a number formatted in such a way that it can be dialed from a mobile phone in a specific region. If the number cannot be reached from the region (e.g. some countries block toll-free numbers from being called outside of the country), the method returns an empty string.
func FormatOutOfCountryCallingNumber ¶
func FormatOutOfCountryCallingNumber( number *PhoneNumber, regionCallingFrom string) string
Formats a phone number for out-of-country dialing purposes. If no regionCallingFrom is supplied, we format the number in its INTERNATIONAL format. If the country calling code is the same as that of the region where the number is from, then NATIONAL formatting will be applied.
If the number itself has a country calling code of zero or an otherwise invalid country calling code, then we return the number with no formatting applied.
Note this function takes care of the case for calling inside of NANPA and between Russia and Kazakhstan (who share the same country calling code). In those cases, no international prefix is used. For regions which have multiple international prefixes, the number in its INTERNATIONAL format will be returned instead.
func FormatOutOfCountryKeepingAlphaChars ¶
func FormatOutOfCountryKeepingAlphaChars( number *PhoneNumber, regionCallingFrom string) string
Formats a phone number for out-of-country dialing purposes.
Note that in this version, if the number was entered originally using alpha characters and this version of the number is stored in raw_input, this representation of the number will be used rather than the digit representation. Grouping information, as specified by characters such as "-" and " ", will be retained.
Caveats:
- This will not produce good results if the country calling code is both present in the raw input _and_ is the start of the national number. This is not a problem in the regions which typically use alpha numbers.
- This will also not produce good results if the raw input has any grouping information within the first three digits of the national number, and if the function needs to strip preceding digits/words in the raw input before these digits. Normally people group the first three digits together so this is not a huge problem - and will be fixed if it proves to be so.
func GetCountryCodeForRegion ¶
Returns the country calling code for a specific region. For example, this would be 1 for the United States, and 64 for New Zealand.
func GetCountryMobileToken ¶
Returns the mobile token for the provided country calling code if it has one, otherwise returns an empty string. A mobile token is a number inserted before the area code when dialing a mobile number from that country from abroad.
func GetLengthOfGeographicalAreaCode ¶
func GetLengthOfGeographicalAreaCode(number *PhoneNumber) int
Gets the length of the geographical area code from the PhoneNumber object. Clients can split GetNationalSignificantNumber at this offset to separate the geographical area code from the subscriber number.
N.B.: area code is a very ambiguous concept, so the I18N team generally recommends against using it for most purposes, but recommends using the more general national_number instead. Read the following carefully before deciding to use this method:
- geographical area codes change over time, and this method honors those changes; therefore, it doesn't guarantee the stability of the result it produces.
- subscriber numbers may not be diallable from all devices (notably mobile devices, which typically requires the full national_number to be dialled in most regions).
- most non-geographical numbers have no area codes, including numbers from non-geographical entities
- some geographical numbers have no area codes.
func GetLengthOfNationalDestinationCode ¶
func GetLengthOfNationalDestinationCode(number *PhoneNumber) int
Gets the length of the national destination code (NDC) from the PhoneNumber. Clients can split GetNationalSignificantNumber at this offset to separate the NDC from the subscriber number. The NDC is normally the first digit group after the country calling code in international format.
Refer to the unittests to see the difference between this function and GetLengthOfGeographicalAreaCode().
func GetNationalSignificantNumber ¶
func GetNationalSignificantNumber(number *PhoneNumber) string
Gets the national significant number of the a phone number. Note a national significant number doesn't contain a national prefix or any formatting.
func GetNddPrefixForRegion ¶
Returns the national dialling prefix for a specific region. For example, this would be 1 for the United States, and 0 for New Zealand. Set stripNonDigits to true to strip symbols like "~" (which indicates a wait for a dialling tone) from the prefix returned. If no national prefix is present, we return null.
Warning: Do not use this method for do-your-own formatting - for some regions, the national dialling prefix is used only for certain types of numbers. Use the library's formatting functions to prefix the national prefix when required.
func GetRegionCodeForCountryCode ¶
Returns the region code that matches the specific country calling code. In the case of no region code being found, ZZ will be returned. In the case of multiple regions, the one designated in the metadata as the "main" region for this calling code will be returned. If the countryCallingCode entered is valid but doesn't match a specific region (such as in the case of non-geographical calling codes like 800) the value "001" will be returned (corresponding to the value for World in the UN M.49 schema).
func GetRegionCodeForNumber ¶
func GetRegionCodeForNumber(number *PhoneNumber) string
Returns the region where a phone number is from. This could be used for geocoding at the region level.
func GetRegionCodesForCountryCode ¶
Returns a list with the region codes that match the specific country calling code. For non-geographical country calling codes, the region code 001 is returned. Also, in the case of no region code being found, an empty list is returned.
func GetSupportedCallingCodes ¶
GetSupportedCallingCodes returns all country calling codes the library has metadata for, covering both non-geographical entities (global network calling codes) and those used for geographical entities. This could be used to populate a drop-down box of country calling codes for a phone-number widget, for instance.
func GetSupportedGlobalNetworkCallingCodes ¶
GetSupportedGlobalNetworkCallingCodes returns all global network calling codes the library has metadata for.
func GetSupportedRegions ¶
GetSupportedRegions returns all regions the library has metadata for.
func GetSupportedTypesForNonGeoEntity ¶
func GetSupportedTypesForNonGeoEntity(countryCallingCode int) map[PhoneNumberType]bool
GetSupportedTypesForNonGeoEntity returns the types for a country-code belonging to a non-geographical entity which the library has metadata for. Will not include FIXED_LINE_OR_MOBILE or UNKNOWN. No types are returned for country calling codes that do not map to a known non-geographical entity.
func GetSupportedTypesForRegion ¶
func GetSupportedTypesForRegion(regionCode string) map[PhoneNumberType]bool
GetSupportedTypesForRegion returns the types for a given region which the library has metadata for. Will not include FIXED_LINE_OR_MOBILE or UNKNOWN. No types are returned for invalid or unknown region codes.
func IsAlphaNumber ¶
Checks if the number is a valid vanity (alpha) number such as 800 MICROSOFT. A valid vanity number will start with at least 3 digits and will have three or more alpha characters. This does not do region-specific checks - to work out if this number is actually valid for a region, it should be parsed and methods such as IsPossibleNumberWithReason() and IsValidNumber() should be used.
func IsMobileNumberPortableRegion ¶
Returns true if the supplied region supports mobile number portability. Returns false for invalid, unknown or regions that don't support mobile number portability.
func IsNANPACountry ¶
Checks if this is a region under the North American Numbering Plan Administration (NANPA).
func IsNumberGeographical ¶
func IsNumberGeographical(phoneNumber *PhoneNumber) bool
Tests whether a phone number has a geographical association. It checks if the number is associated to a certain region in the country where it belongs to. Note that this doesn't verify if the number is actually in use.
A similar method is implemented as PhoneNumberOfflineGeocoder.canBeGeocoded, which performs a looser check, since it only prevents cases where prefixes overlap for geocodable and non-geocodable numbers. Also, if new phone number types were added, we should check if this other method should be updated too.
func IsNumberGeographicalForType ¶
func IsNumberGeographicalForType(phoneNumberType PhoneNumberType, countryCallingCode int) bool
Overload of IsNumberGeographical(PhoneNumber), since calculating the phone number type is expensive; if we have already done this, we don't want to do it again.
func IsPossibleNumber ¶
func IsPossibleNumber(number *PhoneNumber) bool
Convenience wrapper around IsPossibleNumberWithReason(). Instead of returning the reason for failure, this method returns a boolean value.
func IsPossibleNumberForType ¶
func IsPossibleNumberForType(number *PhoneNumber, numberType PhoneNumberType) bool
IsPossibleNumberForType returns true if the number is a possible number of the given type (a more lenient check than IsValidNumberForRegion).
func IsPossibleNumberFromRegion ¶
IsPossibleNumberFromRegion checks whether a phone number is a possible number given a number in the form of a string, and the region where the number could be dialled from. It provides a more lenient check than IsValidNumber. See IsPossibleNumber for details.
This method first parses the number, then invokes IsPossibleNumber with the resultant PhoneNumber object.
regionDialingFrom is the region we expect the number to be dialled from. Note this is different from the region where the number belongs. For example, the number +1 650 253 0000 belongs to the US. When written in this form, it can be dialled from any region. When written as 650 253 0000, it can only be dialled from within the US.
func IsValidNumber ¶
func IsValidNumber(number *PhoneNumber) bool
Tests whether a phone number matches a valid pattern. Note this doesn't verify the number is actually in use, which is impossible to tell by just looking at a number itself.
func IsValidNumberForRegion ¶
func IsValidNumberForRegion(number *PhoneNumber, regionCode string) bool
Tests whether a phone number is valid for a certain region. Note this doesn't verify the number is actually in use, which is impossible to tell by just looking at a number itself. If the country calling code is not the same as the country calling code for the region, this immediately exits with false. After this, the specific number pattern rules for the region are examined. This is useful for determining for example whether a particular number is valid for Canada, rather than just a valid NANPA number. Warning: In most cases, you want to use IsValidNumber() instead. For example, this method will mark numbers from British Crown dependencies such as the Isle of Man as invalid for the region "GB" (United Kingdom), since it has its own region code, "IM", which may be undesirable.
func NormalizeDiallableCharsOnly ¶
Normalizes a string of characters representing a phone number. This strips all characters which are not diallable on a mobile phone keypad (including all non-ASCII digits).
func NormalizeDigitsOnly ¶
Normalizes a string of characters representing a phone number. This converts wide-ascii and arabic-indic numerals to European numerals, and strips punctuation and alpha characters.
func ParseAndKeepRawInputToNumber ¶
func ParseAndKeepRawInputToNumber( numberToParse, defaultRegion string, phoneNumber *PhoneNumber) error
Same as ParseAndKeepRawInput(String, String), but accepts a mutable PhoneNumber as a parameter to decrease object creation when invoked many times.
func ParseToNumber ¶
func ParseToNumber(numberToParse, defaultRegion string, phoneNumber *PhoneNumber) error
Same as Parse(string, string), but accepts mutable PhoneNumber as a parameter to decrease object creation when invoked many times.
func TruncateTooLongNumber ¶
func TruncateTooLongNumber(number *PhoneNumber) bool
Attempts to extract a valid number from a phone number that is too long to be valid, and resets the PhoneNumber object passed in to that valid version. If no valid number could be extracted, the PhoneNumber object passed in will not be modified.
Types ¶
type MatchType ¶
type MatchType int
func IsNumberMatch ¶
Takes two phone numbers as strings and compares them for equality. This is a convenience wrapper for IsNumberMatch(PhoneNumber, PhoneNumber). No default region is known.
func IsNumberMatchWithNumbers ¶
func IsNumberMatchWithNumbers(firstNumberIn, secondNumberIn *PhoneNumber) MatchType
Takes two phone numbers and compares them for equality.
Returns EXACT_MATCH if the country_code, NSN, presence of a leading zero for Italian numbers and any extension present are the same. Returns NSN_MATCH if either or both has no region specified, and the NSNs and extensions are the same. Returns SHORT_NSN_MATCH if either or both has no region specified, or the region specified is the same, and one NSN could be a shorter version of the other number. This includes the case where one has an extension specified, and the other does not. Returns NO_MATCH otherwise. For example, the numbers +1 345 657 1234 and 657 1234 are a SHORT_NSN_MATCH. The numbers +1 345 657 1234 and 345 657 are a NO_MATCH.
func IsNumberMatchWithOneNumber ¶
func IsNumberMatchWithOneNumber( firstNumber *PhoneNumber, secondNumber string) MatchType
Takes two phone numbers and compares them for equality. This is a convenience wrapper for IsNumberMatch(PhoneNumber, PhoneNumber). No default region is known.
type NumberFormat ¶
type NumberFormat = metadata.NumberFormat
type PhoneMetadata ¶
type PhoneMetadata = metadata.PhoneMetadata
type PhoneMetadataCollection ¶
type PhoneMetadataCollection = metadata.PhoneMetadataCollection
func MetadataCollection ¶
func MetadataCollection() (*PhoneMetadataCollection, error)
type PhoneNumber ¶
type PhoneNumber struct {
CountryCode *int32
NationalNumber *uint64
Extension *string
ItalianLeadingZero *bool
NumberOfLeadingZeros *int32
RawInput *string
CountryCodeSource *PhoneNumber_CountryCodeSource
PreferredDomesticCarrierCode *string
}
func GetExampleNumber ¶
func GetExampleNumber(regionCode string) *PhoneNumber
Gets a valid number for the specified region.
func GetExampleNumberForNonGeoEntity ¶
func GetExampleNumberForNonGeoEntity(countryCallingCode int) *PhoneNumber
Gets a valid number for the specified country calling code for a non-geographical entity.
func GetExampleNumberForType ¶
func GetExampleNumberForType(typ PhoneNumberType) *PhoneNumber
Gets a valid number for the specified number type (it may belong to any country).
func GetExampleNumberForTypeInRegion ¶
func GetExampleNumberForTypeInRegion(regionCode string, typ PhoneNumberType) *PhoneNumber
Gets a valid number for the specified region and number type.
This is the upstream getExampleNumberForType(String, PhoneNumberType) overload; GetExampleNumberForType is the region-less variant.
func GetInvalidExampleNumber ¶
func GetInvalidExampleNumber(regionCode string) *PhoneNumber
GetInvalidExampleNumber returns an invalid number for the specified region. This is useful for unit-testing purposes, where you want to test what happens with an invalid number. Returns nil when an unsupported region or the region 001 (Earth) is passed in.
func Parse ¶
func Parse(numberToParse, defaultRegion string) (*PhoneNumber, error)
Parses a string and returns it in proto buffer format. This method will throw a NumberParseException if the number is not considered to be a possible number. Note that validation of whether the number is actually a valid number for a particular region is not performed. This can be done separately with IsValidNumber().
func ParseAndKeepRawInput ¶
func ParseAndKeepRawInput( numberToParse, defaultRegion string) (*PhoneNumber, error)
Parses a string and returns it in proto buffer format. This method differs from Parse() in that it always populates the raw_input field of the protocol buffer with numberToParse as well as the country_code_source field.
func (*PhoneNumber) GetCountryCode ¶
func (x *PhoneNumber) GetCountryCode() int32
func (*PhoneNumber) GetCountryCodeSource ¶
func (x *PhoneNumber) GetCountryCodeSource() PhoneNumber_CountryCodeSource
func (*PhoneNumber) GetExtension ¶
func (x *PhoneNumber) GetExtension() string
func (*PhoneNumber) GetItalianLeadingZero ¶
func (x *PhoneNumber) GetItalianLeadingZero() bool
func (*PhoneNumber) GetNationalNumber ¶
func (x *PhoneNumber) GetNationalNumber() uint64
func (*PhoneNumber) GetNumberOfLeadingZeros ¶
func (x *PhoneNumber) GetNumberOfLeadingZeros() int32
func (*PhoneNumber) GetPreferredDomesticCarrierCode ¶
func (x *PhoneNumber) GetPreferredDomesticCarrierCode() string
func (*PhoneNumber) GetRawInput ¶
func (x *PhoneNumber) GetRawInput() string
type PhoneNumberDesc ¶
type PhoneNumberDesc = metadata.PhoneNumberDesc
type PhoneNumberFormat ¶
type PhoneNumberFormat int
const ( E164 PhoneNumberFormat = iota INTERNATIONAL NATIONAL RFC3966 )
type PhoneNumberType ¶
type PhoneNumberType int
const ( FIXED_LINE PhoneNumberType = iota MOBILE FIXED_LINE_OR_MOBILE TOLL_FREE PREMIUM_RATE SHARED_COST VOIP PERSONAL_NUMBER PAGER UAN VOICEMAIL UNKNOWN )
func GetNumberType ¶
func GetNumberType(number *PhoneNumber) PhoneNumberType
Gets the type of a phone number.
type PhoneNumber_CountryCodeSource ¶
type PhoneNumber_CountryCodeSource int32
const ( PhoneNumber_UNSPECIFIED PhoneNumber_CountryCodeSource = 0 PhoneNumber_FROM_NUMBER_WITH_PLUS_SIGN PhoneNumber_CountryCodeSource = 1 PhoneNumber_FROM_NUMBER_WITH_IDD PhoneNumber_CountryCodeSource = 5 PhoneNumber_FROM_NUMBER_WITHOUT_PLUS_SIGN PhoneNumber_CountryCodeSource = 10 PhoneNumber_FROM_DEFAULT_COUNTRY PhoneNumber_CountryCodeSource = 20 )
func (PhoneNumber_CountryCodeSource) Enum ¶
func (x PhoneNumber_CountryCodeSource) Enum() *PhoneNumber_CountryCodeSource
func (PhoneNumber_CountryCodeSource) String ¶
func (x PhoneNumber_CountryCodeSource) String() string
type ValidationResult ¶
type ValidationResult int
const ( IS_POSSIBLE ValidationResult = iota IS_POSSIBLE_LOCAL_ONLY INVALID_COUNTRY_CODE TOO_SHORT INVALID_LENGTH TOO_LONG )
func IsPossibleNumberForTypeWithReason ¶
func IsPossibleNumberForTypeWithReason(number *PhoneNumber, numberType PhoneNumberType) ValidationResult
IsPossibleNumberForTypeWithReason checks whether a phone number is a possible number of a particular type. For most number types, this is the same result as IsPossibleNumberWithReason. See that method for details.
func IsPossibleNumberWithReason ¶
func IsPossibleNumberWithReason(number *PhoneNumber) ValidationResult
Check whether a phone number is a possible number. It provides a more lenient check than IsValidNumber() in the following sense:
- It only checks the length of phone numbers. In particular, it doesn't check starting digits of the number.
- It doesn't attempt to figure out the type of the number, but uses general rules which applies to all types of phone numbers in a region. Therefore, it is much faster than isValidNumber.
- For fixed line numbers, many regions have the concept of area code, which together with subscriber number constitute the national significant number. It is sometimes okay to dial the subscriber number only when dialing in the same area. This function will return true if the subscriber-number-only version is passed in. On the other hand, because isValidNumber validates using information on both starting digits (for fixed line numbers, that would most likely be area codes) and length (obviously includes the length of area codes for fixed line numbers), it will return false for the subscriber-number-only version.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
regexcache
Package regexcache caches compiled regular expressions keyed by their pattern string, so the libphonenumber port avoids recompiling the same metadata-derived patterns on every call.
|
Package regexcache caches compiled regular expressions keyed by their pattern string, so the libphonenumber port avoids recompiling the same metadata-derived patterns on every call. |