From ab275ef276f176ded95d5d254db0ba1cca5285c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=85=89=E6=98=A5?= Date: Thu, 4 Aug 2022 14:40:55 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E5=A2=9E=E5=8A=A0[=E4=B8=AD=E5=9B=BD?= =?UTF-8?q?=E5=B9=BF=E7=94=B5]=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 10 ++++++++++ gopreg.go | 33 +++++++++++++++++++++++---------- gopreg_test.go | 20 ++++++++++++++++++++ version.go | 2 +- 4 files changed, 54 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 238cdda..60abd5a 100644 --- a/README.md +++ b/README.md @@ -45,5 +45,15 @@ func TestChinaUnicomNumber(t *testing.T) { func TestChinaTelecomNumber(t *testing.T) { t.Log(goverify.ChinaTelecomNumber("13800138000")) } + +// TestChinaBroadnetNumber 验证中国广电手机号码 +func TestChinaBroadnetNumber(t *testing.T) { + t.Log(goverify.ChinaBroadnetNumber("13800138000")) +} + +// TestChinaVirtualNumber 验证虚拟运营商手机号码 +func TestChinaVirtualNumber(t *testing.T) { + t.Log(goverify.ChinaVirtualNumber("13800138000")) +} ``` diff --git a/gopreg.go b/gopreg.go index b16b79f..a4c9155 100644 --- a/gopreg.go +++ b/gopreg.go @@ -5,10 +5,11 @@ import ( ) const ( - mobile = "mobile" // 中国移动 - unicom = "unicom" // 中国联通 - telecom = "telecom" // 中国电信 - virtual = "virtual" // 虚拟 + Mobile = "mobile" // 中国移动 + Unicom = "unicom" // 中国联通 + Telecom = "telecom" // 中国电信 + Broadnet = "broadnet" // 中国广电 + Virtual = "virtual" // 虚拟 ) // ChinaMobile 验证手机号码 @@ -18,19 +19,23 @@ const ( func ChinaMobile(number string) (status bool, operator string) { status = ChinaMobileNumber(number) // 中国移动运营商 if status { - return status, mobile + return status, Mobile } status = ChinaUnicomNumber(number) // 中国联通运营商 if status { - return status, unicom + return status, Unicom } status = ChinaTelecomNumber(number) // 中国电信运营商 if status { - return status, telecom + return status, Telecom + } + status = ChinaBroadnetNumber(number) // 中国广电运营商 + if status { + return status, Broadnet } status = ChinaVirtualNumber(number) // 虚拟运营商 if status { - return status, virtual + return status, Virtual } return } @@ -62,12 +67,20 @@ func ChinaTelecomNumber(number string) bool { return reg.MatchString(number) } +// ChinaBroadnetNumber 验证中国广电手机号码 +// https://www.qqzeng.com/tongji.html +// 广电:192 +func ChinaBroadnetNumber(number string) bool { + regular := "^[1](([9][2]))[0-9]{8}$" + reg := regexp.MustCompile(regular) + return reg.MatchString(number) +} + // ChinaVirtualNumber 验证虚拟运营商手机号码 // https://www.qqzeng.com/tongji.html // 移动/联通/电信: 162 165 167 170 171 -// 广电:192 func ChinaVirtualNumber(number string) bool { - regular := "^[1](([6][2,5,7])|([7][0-1])|([9][2]))[0-9]{8}$" + regular := "^[1](([6][2,5,7])|([7][0-1]))[0-9]{8}$" reg := regexp.MustCompile(regular) return reg.MatchString(number) } diff --git a/gopreg_test.go b/gopreg_test.go index 3922d1c..a76dad3 100644 --- a/gopreg_test.go +++ b/gopreg_test.go @@ -5,6 +5,7 @@ import ( "testing" ) +// TestChinaMobile 验证手机号码 func TestChinaMobile(t *testing.T) { for i := 1; i <= 1; i++ { for ii := 0; ii <= 9; ii++ { @@ -26,6 +27,7 @@ func BenchmarkChinaMobile(b *testing.B) { } } +// TestChinaMobileNumber 验证中国移动手机号码 func TestChinaMobileNumber(t *testing.T) { for i := 1; i <= 1; i++ { for ii := 0; ii <= 9; ii++ { @@ -40,6 +42,7 @@ func TestChinaMobileNumber(t *testing.T) { } } +// TestChinaUnicomNumber 验证中国联通手机号码 func TestChinaUnicomNumber(t *testing.T) { for i := 1; i <= 1; i++ { for ii := 0; ii <= 9; ii++ { @@ -54,6 +57,7 @@ func TestChinaUnicomNumber(t *testing.T) { } } +// TestChinaTelecomNumber 验证中国电信手机号码 func TestChinaTelecomNumber(t *testing.T) { for i := 1; i <= 1; i++ { for ii := 0; ii <= 9; ii++ { @@ -68,6 +72,22 @@ func TestChinaTelecomNumber(t *testing.T) { } } +// TestChinaBroadnetNumber 验证中国广电手机号码 +func TestChinaBroadnetNumber(t *testing.T) { + for i := 1; i <= 1; i++ { + for ii := 0; ii <= 9; ii++ { + for iii := 0; iii <= 9; iii++ { + one := i + two := ii + three := iii + number := fmt.Sprintf("%d%d%d00138000", one, two, three) + t.Logf("[中国广电]%s 状态:%v", number, ChinaBroadnetNumber(number)) + } + } + } +} + +// TestChinaVirtualNumber 验证虚拟运营商手机号码 func TestChinaVirtualNumber(t *testing.T) { for i := 1; i <= 1; i++ { for ii := 0; ii <= 9; ii++ { diff --git a/version.go b/version.go index ade40ee..3fd86bd 100644 --- a/version.go +++ b/version.go @@ -1,3 +1,3 @@ package goverify -const Version = "1.0.4" +const Version = "1.0.5"