Documentation
¶
Index ¶
- func ISOCountryCode(countryCode string, nationalDestinationCode string) string
- func ParseTolerantly(value string) (countryCode string, nationalDestinationCode string, subscriberNumber string, ...)
- func ParseWithIsoCountryCodeTolerantly(isoCountryCode string, value string) (countryCode string, nationalDestinationCode string, subscriberNumber string, ...)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ISOCountryCode ¶
ISOCountryCode is given an E.164 country-code (ex: "1", "82", "98"), and a national-destination-code (ex: "604") and returns the corresponding ISO 3166-1 alpha-2 country-code (ex: "CA", "KR", "IR").
For example:
isoCountryCode := e164.ISOCountryCode("1", "604")
// isoCountryCode == "CA"
Example (Ca) ¶
package main
import (
"fmt"
"github.com/reiver/go-e164"
)
func main() {
e164CountryCode := "1"
e164NationalDestinationCode := "604" // Also called an area-code
isoCountryCode := e164.ISOCountryCode(e164CountryCode, e164NationalDestinationCode)
fmt.Printf("ISO 3166-1 alpha-2 country-code: %s\n", isoCountryCode)
}
Output: ISO 3166-1 alpha-2 country-code: CA
Example (Kr) ¶
package main
import (
"fmt"
"github.com/reiver/go-e164"
)
func main() {
e164CountryCode := "82"
e164NationalDestinationCode := "2" // Also called an area-code
isoCountryCode := e164.ISOCountryCode(e164CountryCode, e164NationalDestinationCode)
fmt.Printf("ISO 3166-1 alpha-2 country-code: %s\n", isoCountryCode)
}
Output: ISO 3166-1 alpha-2 country-code: KR
Example (Us) ¶
package main
import (
"fmt"
"github.com/reiver/go-e164"
)
func main() {
e164CountryCode := "1"
e164NationalDestinationCode := "206" // Also called an area-code
isoCountryCode := e164.ISOCountryCode(e164CountryCode, e164NationalDestinationCode)
fmt.Printf("ISO 3166-1 alpha-2 country-code: %s\n", isoCountryCode)
}
Output: ISO 3166-1 alpha-2 country-code: US
func ParseTolerantly ¶
func ParseTolerantly(value string) (countryCode string, nationalDestinationCode string, subscriberNumber string, err error)
ParseTolerantly parses `value` for a E.164 phone-number tolerantly, such that it allows spaces between the country-code, the national-destination-code and the subscriber-number.
The basic format is:
[+][country code][area code][local phone number]
For example:
var phoneNumber string = "+16045551234" countryCode, nationalDestinationCode, subscriberNumber, err := e164.ParseTolerantly(phoneNumber) // countryCode == "1" // nationalDestinationCode == "604" // subscriberNumber == "5551234"
Example (Ca) ¶
package main
import (
"fmt"
"github.com/reiver/go-e164"
)
func main() {
phoneNumber := "+16045551234"
countryCode, nationalDestinationCode, subscriberNumber, err := e164.ParseTolerantly(phoneNumber)
if nil != err {
fmt.Printf("ERROR: %s\n", err)
return
}
fmt.Printf("E.164 country-code: %s\n", countryCode)
fmt.Printf("E.164 national-destination-code: %s\n", nationalDestinationCode)
fmt.Printf("E.164 subscriber-number: %s\n", subscriberNumber)
}
Output: E.164 country-code: 1 E.164 national-destination-code: 604 E.164 subscriber-number: 5551234
Example (Us) ¶
package main
import (
"fmt"
"github.com/reiver/go-e164"
)
func main() {
phoneNumber := "+12061234567"
countryCode, nationalDestinationCode, subscriberNumber, err := e164.ParseTolerantly(phoneNumber)
if nil != err {
fmt.Printf("ERROR: %s\n", err)
return
}
fmt.Printf("E.164 country-code: %s\n", countryCode)
fmt.Printf("E.164 national-destination-code: %s\n", nationalDestinationCode)
fmt.Printf("E.164 subscriber-number: %s\n", subscriberNumber)
}
Output: E.164 country-code: 1 E.164 national-destination-code: 206 E.164 subscriber-number: 1234567
func ParseWithIsoCountryCodeTolerantly ¶
func ParseWithIsoCountryCodeTolerantly(isoCountryCode string, value string) (countryCode string, nationalDestinationCode string, subscriberNumber string, err error)
ParseWithIsoCountryCodeTolerantly parses `value` for a E.164 phone-number (without the country-code) tolerantly, such that it allows spaces between the country-code, the national-destination-code and the subscriber-number. The country-code implied by the ISO 3166-1 alpha-2 country-code,
The basic format is:
[area code][local phone number]
For example:
var countryCode string = "CA" var phoneNumber string = "6045551234" countryCode, nationalDestinationCode, subscriberNumber, err := e164.ParseTolerantly(phoneNumber) // countryCode == "1" // nationalDestinationCode == "604" // subscriberNumber == "5551234"
Types ¶
This section is empty.