From ab0f520055aadcfa22c2b02a8a66cc53c1ceff56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=99=AF=E6=A1=83=E8=8E=89?= Date: Mon, 4 Dec 2017 17:17:00 +0800 Subject: [PATCH] =?UTF-8?q?fix(IsPhone):=E5=AF=B9=E4=BA=8E=E8=B6=85?= =?UTF-8?q?=E9=99=90=E9=95=BF=E5=BA=A6=E6=89=8B=E6=9C=BA=E5=8F=B7=E6=9C=AA?= =?UTF-8?q?=E8=BF=9B=E8=A1=8C=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- regexp.go | 4 ++-- regexp_test.go | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) 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) + } +}