Compare commits

...

13 Commits

Author SHA1 Message Date
dtapps 1651f55ab2 update
5 months ago
李光春 7262f35069 - update
continuous-integration/drone/push Build is passing Details
2 years ago
李光春 b7cdd6bba5 - 增加[获取运营商类型]方法
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details
2 years ago
李光春 34150d18fd - 增加[获取运营商类型名称]方法
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details
2 years ago
李光春 ab275ef276 - 增加[中国广电]验证
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details
2 years ago
李光春 6d7e135992 - update
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details
2 years ago
李光春 ac0398de58 - update
2 years ago
李光春 e2a2df61c8 - update
2 years ago
李光春 fe91ef400c - update
2 years ago
李光春 1c3779dfb4 - update
2 years ago
李光春 2a9f10fa97 - update
2 years ago
李光春 342e69503a - update
2 years ago
李光春 84fd997870 - update
2 years ago

@ -3,9 +3,15 @@ type: docker
name: clone
steps:
- name: test-golang
- name: Test
image: golang:1.18
commands:
- go env -w GO111MODULE=on
- go env -w GOPROXY=https://goproxy.cn,direct
- go test -v ./...
- go test -v ./...
- name: Benchmark
image: golang:1.18
commands:
- go env -w GO111MODULE=on
- go env -w GOPROXY=https://goproxy.cn,direct
- go test -bench=. -benchmem

2
.gitignore vendored

@ -5,4 +5,4 @@
.vscode
*.log
gomod.sh
/vendor/
*_test.go

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2018 李光春
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

@ -2,24 +2,58 @@
<a href="https://www.dtapp.net/">Golang Verify</a>
</h1>
📦 验证
📦 Golang 验证
[comment]: <> (go)
[![godoc](https://pkg.go.dev/badge/go.dtapp.net/goverify?status.svg)](https://pkg.go.dev/go.dtapp.net/goverify)
[![goproxy.cn](https://goproxy.cn/stats/go.dtapp.net/goverify/badges/download-count.svg)](https://goproxy.cn/stats/go.dtapp.net/goverify)
[![goreportcard.com](https://goreportcard.com/badge/go.dtapp.net/goverify )](https://goreportcard.com/report/go.dtapp.net/goverify)
[![deps.dev](https://img.shields.io/badge/deps-go-red.svg)](https://deps.dev/go/go.dtapp.net/goverify)
[![goreportcard.com](https://goreportcard.com/badge/go.dtapp.net/goverify )](https://goreportcard.com/report/go.dtapp.net/goverify)
[![deps.dev](https://img.shields.io/badge/deps-go-red.svg)](https://deps.dev/go/go.dtapp.net%2Fgoverify)
#### 安装使用
#### 安装
```go
go get -v -u go.dtapp.net/goverify
```shell
go get -v -u go.dtapp.net/goverify@v1.0.8
```
#### 导入
#### 使用
```go
package main
import (
"go.dtapp.net/goverify"
"go.dtapp.net/goverify"
"testing"
)
// TestChinaMobile 验证手机号码
func TestChinaMobile(t *testing.T) {
t.Log(goverify.ChinaMobile("13800138000"))
}
// TestChinaMobileNumber 验证中国移动手机号码
func TestChinaMobileNumber(t *testing.T) {
t.Log(goverify.ChinaMobileNumber("13800138000"))
}
// TestChinaUnicomNumber 验证中国联通手机号码
func TestChinaUnicomNumber(t *testing.T) {
t.Log(goverify.ChinaUnicomNumber("13800138000"))
}
// TestChinaTelecomNumber 验证中国电信手机号码
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"))
}
```

@ -0,0 +1,32 @@
package goverify
// 运营商名称
var typeName = map[string]string{
Mobile: "移动",
Unicom: "联通",
Telecom: "电信",
Broadnet: "广电",
Virtual: "虚拟",
}
// GetTypeName 获取运营商类型名称
func GetTypeName(Type string) string {
return typeName[Type]
}
// GetType 获取运营商类型
func GetType(name string) (Type string) {
switch name {
case "移动", "移动运营商", "中国移动", "中国移动运营商":
return Mobile
case "联通", "联通运营商", "中国联通", "中国联通运营商":
return Unicom
case "电信", "电信运营商", "中国电信", "中国电信运营商":
return Telecom
case "广电", "广电运营商", "中国广电", "中国广电运营商":
return Broadnet
case "虚拟", "虚拟运营商":
return Virtual
}
return Type
}

@ -0,0 +1,11 @@
package goverify
import "testing"
func TestGetType(t *testing.T) {
t.Log(GetType("移动"))
}
func TestGetTypeName(t *testing.T) {
t.Log(GetTypeName(Mobile))
}

@ -1,3 +1,3 @@
module go.dtapp.net/goverify
go 1.18
go 1.21

@ -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)
}

@ -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++ {

@ -1,3 +1,3 @@
package goverify
const Version = "1.0.2"
const Version = "1.0.8"

Loading…
Cancel
Save