mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-04 12:52:28 +08:00
doc: add docment for new or fixed function
This commit is contained in:
@@ -2357,7 +2357,7 @@ func main() {
|
||||
编辑
|
||||
func ToMarkdownTable(data []map[string]interface{}, headerMap map[string]string, columnOrder []string) string
|
||||
```
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行]()</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/todo)</span></b>
|
||||
|
||||
|
||||
```go
|
||||
|
||||
@@ -31,6 +31,7 @@ import (
|
||||
- [IsStruct](#IsStruct)
|
||||
- [Tag](#Tag)
|
||||
- [Name](#Name)
|
||||
- [TypeName](#TypeName)
|
||||
- [Value](#Value)
|
||||
- [Kind](#Kind)
|
||||
- [IsEmbedded](#IsEmbedded)
|
||||
@@ -53,7 +54,7 @@ import (
|
||||
func New(value any, tagName ...string) *Struct
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/O29l8kk-Z17)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -68,7 +69,11 @@ func main() {
|
||||
}
|
||||
p1 := &People{Name: "11"}
|
||||
s := structs.New(p1)
|
||||
// to do something
|
||||
|
||||
fmt.Println(s.ToMap())
|
||||
|
||||
// Output:
|
||||
// map[name:11] <nil>
|
||||
}
|
||||
```
|
||||
|
||||
@@ -88,7 +93,7 @@ func (s *Struct) ToMap() (map[string]any, error)
|
||||
func ToMap(v any) (map[string]any, error)
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/qQbLySBgerZ)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -129,7 +134,7 @@ func main() {
|
||||
func (s *Struct) Fields() []*Field
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/w3Kk_CyVY7D)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -161,10 +166,10 @@ func main() {
|
||||
<b>函数签名:</b>
|
||||
|
||||
```go
|
||||
func (s *Struct) Field(name string) *Field
|
||||
func (s *Struct) Field(name string) (*Field, bool)
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/KocZMSYarza)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -180,12 +185,14 @@ func main() {
|
||||
}
|
||||
p1 := &People{Name: "11"}
|
||||
s := structs.New(p1)
|
||||
f := s.Field("Name")
|
||||
f, found := s.Field("Name")
|
||||
|
||||
fmt.Println(f.Value())
|
||||
fmt.Println(found)
|
||||
|
||||
// Output:
|
||||
// 11
|
||||
// true
|
||||
}
|
||||
```
|
||||
|
||||
@@ -199,7 +206,7 @@ func main() {
|
||||
func (s *Struct) IsStruct() bool
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/bU2FSdkbK1C)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -233,7 +240,7 @@ func main() {
|
||||
func (f *Field) Tag() *Tag
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/DVrx5HvvUJr)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -270,7 +277,7 @@ func main() {
|
||||
func (f *Field) Value() any
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/qufYEU2o4Oi)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -306,7 +313,7 @@ func main() {
|
||||
func (f *Field) IsEmbedded() bool
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/wV2PrbYm3Ec)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -351,7 +358,7 @@ func main() {
|
||||
func (f *Field) IsExported() bool
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/csK4AXYaNbJ)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -390,7 +397,7 @@ func main() {
|
||||
func (f *Field) IsZero() bool
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/RzqpGISf87r)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -429,7 +436,7 @@ func main() {
|
||||
func (f *Field) Name() string
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/zfIGlqsatee)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -468,7 +475,7 @@ func main() {
|
||||
func (f *Field) Kind() reflect.Kind
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/wg4NlcUNG5o)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -497,6 +504,42 @@ func main() {
|
||||
}
|
||||
```
|
||||
|
||||
### <span id="TypeName">TypeName</span>
|
||||
|
||||
<p>获取结构体类型名。</p>
|
||||
|
||||
<b>函数签名:</b>
|
||||
|
||||
```go
|
||||
func (s *Struct) TypeName() string
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/todo)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/duke-git/lancet/v2/structs"
|
||||
)
|
||||
|
||||
func main() {
|
||||
type Parent struct {
|
||||
Name string
|
||||
Age int
|
||||
}
|
||||
|
||||
p := &Parent{Age: 11}
|
||||
s := structs.New(p1)
|
||||
|
||||
fmt.Println(s.TypeName())
|
||||
|
||||
// Output:
|
||||
// Parent
|
||||
}
|
||||
```
|
||||
|
||||
### <span id="IsSlice">IsSlice</span>
|
||||
|
||||
<p>判断属性是否是切片</p>
|
||||
@@ -507,7 +550,7 @@ func main() {
|
||||
func (f *Field) IsSlice() bool
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/MKz4CgBIUrU)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -544,7 +587,7 @@ func main() {
|
||||
func (f *Field) IsTargetType(targetType reflect.Kind) bool
|
||||
```
|
||||
|
||||
<b>示例:</b>
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/Ig75P-agN39)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
@@ -65,6 +65,8 @@ import (
|
||||
- [IsAmericanExpress](#IsAmericanExpress)
|
||||
- [IsUnionPay](#IsUnionPay)
|
||||
- [IsChinaUnionPay](#IsChinaUnionPay)
|
||||
- [IsPassport](#IsPassport)
|
||||
- [IsChineseHMPassport](#IsChineseHMPassport)
|
||||
|
||||
<div STYLE="page-break-after: always;"></div>
|
||||
|
||||
@@ -844,20 +846,20 @@ import (
|
||||
|
||||
func main() {
|
||||
result1 := validator.IsAlphaNumeric("ABC")
|
||||
result2 := validator.IsAlphaNumeric("123")
|
||||
result3 := validator.IsAlphaNumeric("abc123")
|
||||
result4 := validator.IsAlphaNumeric("abc123@#$")
|
||||
result2 := validator.IsAlphaNumeric("123")
|
||||
result3 := validator.IsAlphaNumeric("abc123")
|
||||
result4 := validator.IsAlphaNumeric("abc123@#$")
|
||||
|
||||
fmt.Println(result1)
|
||||
fmt.Println(result2)
|
||||
fmt.Println(result3)
|
||||
fmt.Println(result4)
|
||||
fmt.Println(result1)
|
||||
fmt.Println(result2)
|
||||
fmt.Println(result3)
|
||||
fmt.Println(result4)
|
||||
|
||||
// Output:
|
||||
// true
|
||||
// true
|
||||
// true
|
||||
// false
|
||||
// Output:
|
||||
// true
|
||||
// true
|
||||
// true
|
||||
// false
|
||||
}
|
||||
```
|
||||
|
||||
@@ -1567,3 +1569,80 @@ func main() {
|
||||
// false
|
||||
}
|
||||
```
|
||||
|
||||
### <span id="IsPassport">IsPassport</span>
|
||||
|
||||
<p>判断护照(正则判断)。</p>
|
||||
|
||||
<b>函数签名:</b>
|
||||
|
||||
```go
|
||||
func IsPassport(passport, country string) bool
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/todo)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/duke-git/lancet/v2/validator"
|
||||
)
|
||||
|
||||
func main() {
|
||||
result1 := validator.IsPassport("P123456789", "CN")
|
||||
result2 := validator.IsPassport("123456789", "US")
|
||||
result3 := validator.IsPassport("AB1234567", "RU")
|
||||
result4 := validator.IsPassport("123456789", "CN")
|
||||
|
||||
fmt.Println(result1)
|
||||
fmt.Println(result2)
|
||||
fmt.Println(result3)
|
||||
fmt.Println(result4)
|
||||
|
||||
// Output:
|
||||
// true
|
||||
// true
|
||||
// true
|
||||
// false
|
||||
}
|
||||
```
|
||||
|
||||
### <span id="IsChineseHMPassport">IsChineseHMPassport</span>
|
||||
|
||||
<p>判断港澳台通行证(正则判断)。</p>
|
||||
|
||||
<b>函数签名:</b>
|
||||
|
||||
```go
|
||||
func IsChineseHMPassport(hmPassport string) bool
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/todo)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/duke-git/lancet/v2/validator"
|
||||
)
|
||||
|
||||
func main() {
|
||||
result1 := validator.IsChineseHMPassport("C12345678")
|
||||
result2 := validator.IsChineseHMPassport("C00000000")
|
||||
result3 := validator.IsChineseHMPassport("M12345678")
|
||||
result4 := validator.IsChineseHMPassport("c12345678")
|
||||
result5 := validator.IsChineseHMPassport("C1234567")
|
||||
|
||||
fmt.Println(result1)
|
||||
fmt.Println(result2)
|
||||
fmt.Println(result3)
|
||||
fmt.Println(result4)
|
||||
fmt.Println(result5)
|
||||
|
||||
// Output:
|
||||
// true
|
||||
// true
|
||||
// true
|
||||
// false
|
||||
// false
|
||||
}
|
||||
```
|
||||
@@ -79,6 +79,8 @@ import (
|
||||
- [SortByKey](#SortByKey)
|
||||
- [GetOrDefault](#GetOrDefault)
|
||||
- [FindValuesBy](#FindValuesBy)
|
||||
- [ToMarkdownTable](#ToMarkdownTable)
|
||||
|
||||
|
||||
<div STYLE="page-break-after: always;"></div>
|
||||
|
||||
@@ -2363,3 +2365,69 @@ func main() {
|
||||
// [b d]
|
||||
}
|
||||
```
|
||||
|
||||
### <span id="ToMarkdownTable">ToMarkdownTable</span>
|
||||
|
||||
<p>Convert a map slice data to a Markdown table string. It supports custom header display names and column display order.</p>
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```go
|
||||
编辑
|
||||
func ToMarkdownTable(data []map[string]interface{}, headerMap map[string]string, columnOrder []string) string
|
||||
```
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/todo)</span></b>
|
||||
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/duke-git/lancet/v2/maputil"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// basic usage: automatically extract column names from data as table headers
|
||||
|
||||
data := []map[string]interface{}{
|
||||
{"name": "Alice", "age": 25, "salary": 50000},
|
||||
{"name": "Bob", "age": 30, "salary": 60000},
|
||||
}
|
||||
|
||||
result := maputil.ToMarkdownTable(data, nil, nil)
|
||||
fmt.Println(result)
|
||||
|
||||
// output:
|
||||
// |name|age|salary|
|
||||
// |---|---|---|
|
||||
// |Alice|25|50000|
|
||||
// |Bob|30|60000|
|
||||
|
||||
// custom header name
|
||||
headerMap := map[string]string{
|
||||
"name": "n",
|
||||
"age": "a",
|
||||
"salary": "s",
|
||||
}
|
||||
result = maputil.ToMarkdownTable(data, headerMap, nil)
|
||||
fmt.Println(result)
|
||||
|
||||
// ouput:
|
||||
// |m|a|s|
|
||||
// |---|---|---|
|
||||
// |Alice|25|50000|
|
||||
// |Bob|30|60000|
|
||||
|
||||
// custom column display order
|
||||
columnOrder := []string{"salary", "name"}
|
||||
result = maputil.ToMarkdownTable(data, nil, columnOrder)
|
||||
fmt.Println(result)
|
||||
|
||||
// 输出:
|
||||
// |salary|name|
|
||||
// |---|---|
|
||||
// |50000|Alice|
|
||||
// |60000|Bob|
|
||||
}
|
||||
```
|
||||
@@ -31,6 +31,7 @@ import (
|
||||
- [IsStruct](#IsStruct)
|
||||
- [Tag](#Tag)
|
||||
- [Name](#Name)
|
||||
- [TypeName](#TypeName)
|
||||
- [Value](#Value)
|
||||
- [Kind](#Kind)
|
||||
- [IsEmbedded](#IsEmbedded)
|
||||
@@ -53,12 +54,13 @@ import (
|
||||
func New(value any, tagName ...string) *Struct
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/O29l8kk-Z17)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/duke-git/lancet/v2/structs"
|
||||
)
|
||||
|
||||
@@ -68,7 +70,11 @@ func main() {
|
||||
}
|
||||
p1 := &People{Name: "11"}
|
||||
s := structs.New(p1)
|
||||
// to do something
|
||||
|
||||
fmt.Println(s.ToMap())
|
||||
|
||||
// Output:
|
||||
// map[name:11] <nil>
|
||||
}
|
||||
```
|
||||
|
||||
@@ -88,7 +94,7 @@ func (s *Struct) ToMap() (map[string]any, error)
|
||||
func ToMap(v any) (map[string]any, error)
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/qQbLySBgerZ)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -130,7 +136,7 @@ func main() {
|
||||
func (s *Struct) Fields() []*Field
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/w3Kk_CyVY7D)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -162,10 +168,10 @@ func main() {
|
||||
<b>Signature:</b>
|
||||
|
||||
```go
|
||||
func (s *Struct) Field(name string) *Field
|
||||
func (s *Struct) Field(name string) (*Field, bool)
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/KocZMSYarza)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -181,12 +187,14 @@ func main() {
|
||||
}
|
||||
p1 := &People{Name: "11"}
|
||||
s := structs.New(p1)
|
||||
f := s.Field("Name")
|
||||
f, found := s.Field("Name")
|
||||
|
||||
fmt.Println(f.Value())
|
||||
fmt.Println(found)
|
||||
|
||||
// Output:
|
||||
// 11
|
||||
// true
|
||||
}
|
||||
```
|
||||
|
||||
@@ -200,7 +208,7 @@ func main() {
|
||||
func (s *Struct) IsStruct() bool
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/bU2FSdkbK1C)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -234,7 +242,7 @@ func main() {
|
||||
func (f *Field) Tag() *Tag
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/DVrx5HvvUJr)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -271,7 +279,7 @@ func main() {
|
||||
func (f *Field) Value() any
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/qufYEU2o4Oi)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -307,7 +315,7 @@ func main() {
|
||||
func (f *Field) IsEmbedded() bool
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/wV2PrbYm3Ec)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -352,7 +360,7 @@ func main() {
|
||||
func (f *Field) IsExported() bool
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/csK4AXYaNbJ)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -391,7 +399,7 @@ func main() {
|
||||
func (f *Field) IsZero() bool
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/RzqpGISf87r)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -430,7 +438,7 @@ func main() {
|
||||
func (f *Field) Name() string
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/zfIGlqsatee)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -469,7 +477,7 @@ func main() {
|
||||
func (f *Field) Kind() reflect.Kind
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/wg4NlcUNG5o)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -498,6 +506,42 @@ func main() {
|
||||
}
|
||||
```
|
||||
|
||||
### <span id="TypeName">TypeName</span>
|
||||
|
||||
<p>Return struct type name.</p>
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```go
|
||||
func (s *Struct) TypeName() string
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/todo)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/duke-git/lancet/v2/structs"
|
||||
)
|
||||
|
||||
func main() {
|
||||
type Parent struct {
|
||||
Name string
|
||||
Age int
|
||||
}
|
||||
|
||||
p := &Parent{Age: 11}
|
||||
s := structs.New(p1)
|
||||
|
||||
fmt.Println(s.TypeName())
|
||||
|
||||
// Output:
|
||||
// Parent
|
||||
}
|
||||
```
|
||||
|
||||
### <span id="IsSlice">IsSlice</span>
|
||||
|
||||
<p>Check if the field is a slice</p>
|
||||
@@ -508,7 +552,7 @@ func main() {
|
||||
func (f *Field) IsSlice() bool
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/MKz4CgBIUrU)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -545,7 +589,7 @@ func main() {
|
||||
func (f *Field) IsTargetType(targetType reflect.Kind) bool
|
||||
```
|
||||
|
||||
<b>Example:</b>
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/Ig75P-agN39)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
@@ -65,6 +65,8 @@ import (
|
||||
- [IsAmericanExpress](#IsAmericanExpress)
|
||||
- [IsUnionPay](#IsUnionPay)
|
||||
- [IsChinaUnionPay](#IsChinaUnionPay)
|
||||
- [IsPassport](#IsPassport)
|
||||
- [IsChineseHMPassport](#IsChineseHMPassport)
|
||||
|
||||
<div STYLE="page-break-after: always;"></div>
|
||||
|
||||
@@ -1569,3 +1571,80 @@ func main() {
|
||||
// false
|
||||
}
|
||||
```
|
||||
|
||||
### <span id="IsPassport">IsPassport</span>
|
||||
|
||||
<p>Passport validation(using regex).</p>
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```go
|
||||
func IsPassport(passport, country string) bool
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/todo)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/duke-git/lancet/v2/validator"
|
||||
)
|
||||
|
||||
func main() {
|
||||
result1 := validator.IsPassport("P123456789", "CN")
|
||||
result2 := validator.IsPassport("123456789", "US")
|
||||
result3 := validator.IsPassport("AB1234567", "RU")
|
||||
result4 := validator.IsPassport("123456789", "CN")
|
||||
|
||||
fmt.Println(result1)
|
||||
fmt.Println(result2)
|
||||
fmt.Println(result3)
|
||||
fmt.Println(result4)
|
||||
|
||||
// Output:
|
||||
// true
|
||||
// true
|
||||
// true
|
||||
// false
|
||||
}
|
||||
```
|
||||
|
||||
### <span id="IsChineseHMPassport">IsChineseHMPassport</span>
|
||||
|
||||
<p>Mainland travel permit for Hong Kong, Macao validation (using regex). </p>
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```go
|
||||
func IsChineseHMPassport(hmPassport string) bool
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/todo)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/duke-git/lancet/v2/validator"
|
||||
)
|
||||
|
||||
func main() {
|
||||
result1 := validator.IsChineseHMPassport("C12345678")
|
||||
result2 := validator.IsChineseHMPassport("C00000000")
|
||||
result3 := validator.IsChineseHMPassport("M12345678")
|
||||
result4 := validator.IsChineseHMPassport("c12345678")
|
||||
result5 := validator.IsChineseHMPassport("C1234567")
|
||||
|
||||
fmt.Println(result1)
|
||||
fmt.Println(result2)
|
||||
fmt.Println(result3)
|
||||
fmt.Println(result4)
|
||||
fmt.Println(result5)
|
||||
|
||||
// Output:
|
||||
// true
|
||||
// true
|
||||
// true
|
||||
// false
|
||||
// false
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user