From 7093a634aa5a4947994b090383bf7eb8aa28753f Mon Sep 17 00:00:00 2001 From: guanguans Date: Tue, 12 Jan 2021 17:46:05 +0800 Subject: [PATCH] Add examples --- README.md | 4 ++-- examples/main.go | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 examples/main.go diff --git a/README.md b/README.md index 1cd7a1b..baa889e 100644 --- a/README.md +++ b/README.md @@ -29,9 +29,9 @@ Let's start with a trivial example: package main import ( - "github.com/guanguans/id-validator" + "fmt" - "gopkg.in/ffmt.v1" + idvalidator "github.com/guanguans/id-validator" ) func main() { diff --git a/examples/main.go b/examples/main.go new file mode 100644 index 0000000..500bd70 --- /dev/null +++ b/examples/main.go @@ -0,0 +1,25 @@ +package main + +import ( + "fmt" + + idvalidator "github.com/guanguans/id-validator" +) + +func main() { + // 验证身份证号合法性 + fmt.Println(idvalidator.IsValid("440308199901101512")) // 大陆居民身份证18位 + fmt.Println(idvalidator.IsValid("610104620927690")) // 大陆居民身份证15位 + fmt.Println(idvalidator.IsValid("810000199408230021")) // 港澳居民居住证18位 + fmt.Println(idvalidator.IsValid("830000199201300022")) // 台湾居民居住证18位 + + // 获取身份证号信息 + fmt.Println(idvalidator.GetInfo("440308199901101512")) + + // 生成可通过校验的假身份证号 + fmt.Println(idvalidator.FakeId()) // 随机生成 + fmt.Println(idvalidator.FakeRequireId(true, "江苏省", "200001", 1)) // 生成出生于2000年1月江苏省的男性居民身份证 + + // 15位号码升级为18位 + fmt.Println(idvalidator.UpgradeId("610104620927690")) +}