Skip to content

Commit

Permalink
Update README with area code example
Browse files Browse the repository at this point in the history
  • Loading branch information
ttacon committed Jul 15, 2018
1 parent e2adc61 commit d2ed36b
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,23 @@ num, err := libphonenumber.Parse("6502530000", "US")
// num is a *libphonenumber.PhoneNumber
formattedNum := libphonenumber.Format(num, libphonenumber.NATIONAL)
```

### To get the area code of a number
```go
// Parse the number.
num, err := libphonenumber.Parse("1234567890", "US")
if err != nil {
// Handle error appropriately.
}

// Get the cleaned number and the length of the area code.
natSigNumber := libphonenumber.GetNationalSignificantNumber(num)
geoCodeLength := libphonenumber.GetLengthOfGeographicalAreaCode(num)

// Extract the area code.
areaCode := ""
if geoCodeLength > 0 {
areaCode = natSigNumber[0:geoCodeLength]
}
fmt.Println(areaCode)
```

0 comments on commit d2ed36b

Please sign in to comment.