# laravel-go-phone

> Go port of propaganistas/laravel-phone: From a local phone number to a consistent E.164 value

- Package: laravel-go-phone (Laravel for Go, alpha), go modules: `github.com/bowerbird-si/laravel-go-phone`
- Maintenance: active; Latest release: 0.1.0 (2026-12-04); Framework: go.laravel.com v0.2.0 or later; Go: Go 1.27 or later; Licence: MIT
- Links: [Repository](https://github.com/bowerbird-si/laravel-go-phone), [pkg.go.dev](https://pkg.go.dev/github.com/bowerbird-si/laravel-go-phone@v0.1.0), [Changelog](https://oss.bowerbird.si/go-phone/docs/changelog/), [Contributing](https://github.com/bowerbird-si/laravel-go-phone/blob/d3b62daef7b7377a876b692feebe673aa709d898/CONTRIBUTING.md), [Security policy](https://github.com/bowerbird-si/laravel-go-phone/blob/d3b62daef7b7377a876b692feebe673aa709d898/SECURITY.md)
- Based on: [Laravel-Phone](https://github.com/Propaganistas/Laravel-Phone): The package this ports: parsing, validation rules, formatting and model storage, following version 6.1.0.; [phonenumbers](https://github.com/nyaruka/phonenumbers): Phone number parsing and the numbering-plan metadata.
- PHP parity: full (30 covered, 21 diverged, 0 planned of 51 abilities; 166 fixtures; follows propaganistas/laravel-phone 6.1.0; verified 2026-12-04)
- Community package, not affiliated with Laravel.
- HTML version: https://oss.bowerbird.si/go-phone/
- Documentation: https://oss.bowerbird.si/go-phone/docs.md

Accept numbers in the formats people use locally. With a Belgian country hint, `0470 12 34 56` becomes `+32470123456` for storage and lookup.

```shell
go get github.com/bowerbird-si/laravel-go-phone@v0.1.0
```

- **Parse and format.** Use `phone.Parse` with country hints for national input. Format the result as E.164, international, national or an RFC 3966 telephone URI.
- **Validate Laravel forms.** Attach `phonevalidation.Rule()` with `rule.Field` and restrict the country or number type. The rule can read a sibling field such as `phone_country`.
- **Store phone numbers on models.** Use `phonemodel.E164` to store canonical text and scan it back into a parsed number. Use `phonemodel.Raw` to keep the text as entered.

### Convert a Belgian number to E.164

Pass `BE` as the country hint for the national number.

```go
package phone_test

import (
	"fmt"

	"github.com/bowerbird-si/laravel-go-phone"
)

func Example() {
	number, err := phone.Parse("0470 12 34 56", "BE")
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(number)
	// Output: +32470123456
}
```

### Validate a mobile number in a form

The rule reads `phone_country` next to `phone` and checks that the number is mobile.

```go
package phonevalidation_test

import (
	"context"
	"fmt"

	phonevalidation "github.com/bowerbird-si/laravel-go-phone/validation"
	"go.laravel.com/validation"
	"go.laravel.com/validation/rule"
)

func Example() {
	form := struct {
		Phone   string `json:"phone"`
		Country string `json:"phone_country"`
	}{Phone: "0470 12 34 56", Country: "BE"}

	errs, err := validation.Validate(context.Background(), &form,
		rule.Field(&form.Phone, rule.Required, phonevalidation.Rule().Mobile()),
	)
	fmt.Println(len(errs), err)
	// Output: 0 <nil>
}
```
