Last active
June 26, 2019 15:15
-
-
Save sysradium/e275d42c803df9cc3f1c11e02e0a43dc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"github.com/pkg/errors" | |
"github.com/ttacon/libphonenumber" | |
) | |
var ( | |
InvalidPhoneNumber = errors.New("phone number is invalid") | |
) | |
func GetNormalisedPhoneNumber(number string) (string, error) { | |
num, err := libphonenumber.Parse(number, "") | |
if err != nil { | |
return "", errors.Wrap(err, "could not parse phone number") | |
} | |
if !libphonenumber.IsValidNumber(num) { | |
return "", errors.WithStack(InvalidPhoneNumber) | |
} | |
return libphonenumber.Format(num, libphonenumber.E164), nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment