diff --git a/regexp.go b/regexp.go index aa02bd5..f38409d 100644 --- a/regexp.go +++ b/regexp.go @@ -29,9 +29,9 @@ func IsMail(val string) bool { func IsPhone(val string) bool { if strings.HasPrefix(val, "+") { - return IsMatch(val[1:], `\d{13}`) + return IsMatch(val[1:], `^\d{13}$`) } else { - return IsMatch(val, `\d{11}`) + return IsMatch(val, `^\d{11}$`) } } diff --git a/regexp_test.go b/regexp_test.go index e983eba..977737d 100644 --- a/regexp_test.go +++ b/regexp_test.go @@ -51,3 +51,11 @@ func TestIsPhone3(t *testing.T) { t.Errorf("TestIsPhone3:\n Expect => %v\n Got => %v\n", expect, got) } } + +func TestIsPhone4(t *testing.T) { + got := IsPhone("186121855232342342") + expect := false + if got != expect { + t.Errorf("TestIsPhone4:\n Expect => %v\n Got => %v\n", expect, got) + } +}