types.go
func NewPhoneNumber(pn string) (PhoneNumber, error) {
	if len(pn) == 0 {
		return "", ErrEmptyNumber
	}
	num, err := libphonenumber.Parse(pn, "US")
	// Add some better error messages - the ones in libphonenumber are generic
	switch {
	case err == libphonenumber.ErrNotANumber:
		return "", fmt.Errorf("twilio: Invalid phone number: %s", pn)
	case err == libphonenumber.ErrInvalidCountryCode:
		return "", fmt.Errorf("twilio: Invalid country code for number: %s", pn)
	case err != nil:
		return "", err
	}
	return PhoneNumber(libphonenumber.Format(num, libphonenumber.E164)), nil
}
func NewPhoneNumber(pn string) (PhoneNumber, error) {
	if len(pn) == 0 {
		return "", ErrEmptyNumber
	}
	num, err := libphonenumber.Parse(pn, "US")
	// Add some better error messages - the ones in libphonenumber are generic
	switch {
	case err == libphonenumber.ErrNotANumber:
		return "", fmt.Errorf("twilio: Invalid phone number: %s", pn)
	case err == libphonenumber.ErrInvalidCountryCode:
		return "", fmt.Errorf("twilio: Invalid country code for number: %s", pn)
	case err != nil:
		return "", err
	}
	return PhoneNumber(libphonenumber.Format(num, libphonenumber.E164)), nil
}
func NewPhoneNumber ( pn string ) ( PhoneNumber , error ) { if len ( pn ) == 0 { return " " , ErrEmptyNumber } num , err := libphonenumber . Parse ( pn , " " ) // Add some better error messages - the ones in libphonenumber are generic switch { case err == libphonenumber . ErrNotANumber : return " " , fmt . Errorf ( " " , pn ) case err == libphonenumber . ErrInvalidCountryCode : return " " , fmt . Errorf ( " " , pn ) case err != nil : return " " , err } return PhoneNumber ( libphonenumber . Format ( num , libphonenumber . E164 ) ) , nil }
// NewPhoneNumber parses the given value as a phone number or returns an error
// if it cannot be parsed as one. If a phone number does not begin with a plus
// sign, we assume it's a US national number. Numbers are stored in E.164
// format.
NewPhoneNumber parses the given value as a phone number or returns an error if it cannot be parsed as one . If a phone number does not begin with a plus sign we assume it s a US national number . Numbers are stored in E . 164 format .