nyaruka/phonenumbers

Is this a bug?

Closed this issue · 1 comments

elbek commented

I am trying to valiedate phone numbers using this and found weird case:

package util

import (
	"github.com/nyaruka/phonenumbers"
	"testing"
)

func TestValidatePhone(t *testing.T) {
	type args struct {
		phone string
		region string
	}
	tests := []struct {
		name string
		args args
	}{
		{
			name: "3",
			args: args{
				phone:  "+99899984582039480230",
				region: "ZZ",
			},
		},{
			name: "4",
			args: args{
				phone:  "+998999845820394802301",
				region: "ZZ",
			},
		},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			_, err := phonenumbers.Parse(tt.args.phone, tt.args.region)
			println(tt.name, " ", err == nil)
		})
	}
}

In this test 3rd one passes, 4th one fails. Both of them are garbage, not a phone number. Is this expected?

phonenumbers.Parse doesn't validate numbers - it just tries to parse the input. You need to call IsPossibleNumber on the returned parsed number.