Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion util/gvalid/gvalid.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ var (
// The sequence tag is like: [alias@]rule[...#msg...]
func ParseTagValue(tag string) (field, rule, msg string) {
// Complete sequence tag.
// Example: name@required|length:2,20|password3|same:password1#||密码强度不足 | 两次密码不一致
// Example: name@required|length:2,20|password3|same:password1#||Password strength is insufficient | Passwords are not match
match, _ := gregex.MatchString(`\s*((\w+)\s*@){0,1}\s*([^#]+)\s*(#\s*(.*)){0,1}\s*`, tag)
if len(match) > 5 {
msg = strings.TrimSpace(match[5])
Expand Down
6 changes: 3 additions & 3 deletions util/gvalid/gvalid_z_example_feature_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -954,16 +954,16 @@ func ExampleValidator_json() {
var (
ctx = context.Background()
req = BizReq{
JSON1: "{\"name\":\"goframe\",\"author\":\"郭强\"}",
JSON2: "{\"name\":\"goframe\",\"author\":\"郭强\",\"test\"}",
JSON1: "{\"name\":\"goframe\",\"author\":\"Guo Qiang\"}",
JSON2: "{\"name\":\"goframe\",\"author\":\"Guo Qiang\",\"test\"}",
}
)
if err := g.Validator().Data(req).Run(ctx); err != nil {
fmt.Print(err)
}

// Output:
// The JSON2 value `{"name":"goframe","author":"郭强","test"}` is not a valid JSON string
// The JSON2 value `{"name":"goframe","author":"Guo Qiang","test"}` is not a valid JSON string
}

func ExampleValidator_integer() {
Expand Down
14 changes: 7 additions & 7 deletions util/gvalid/gvalid_z_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,9 @@ func ExampleValidator_Data_map1() {
fmt.Println(e.FirstError())
}
// May Output:
// map[required:账号不能为空 length:账号长度应当在 6 到 16 之间]
// passport map[required:账号不能为空 length:账号长度应当在 6 到 16 之间]
// 账号不能为空
// map[required:The passport field is required length:The passport value `` length must be between 6 and 16]
// passport map[required:The passport field is required length:The passport value `` length must be between 6 and 16]
// The passport field is required
}

func ExampleValidator_Data_map2() {
Expand Down Expand Up @@ -273,11 +273,11 @@ func ExampleValidator_Data_map3() {
// May Output:
// {
// "passport": {
// "length": "账号长度应当在 6 到 16 之间",
// "required": "账号不能为空"
// "length": "The passport value `` length must be between 6 and 16",
// "required": "The passport field is required"
// },
// "password": {
// "same": "两次密码输入不相等"
// "same": "The password value `123456` must be the same as field password2 value `1234567`"
// }
// }
}
Expand Down Expand Up @@ -521,5 +521,5 @@ func ExampleValidator_registerRule() {
err := g.Validator().Data(user).Run(gctx.New())
fmt.Println(err.Error())
// May Output:
// 用户名称已被占用
// The Name value `john` is not unique
}
4 changes: 2 additions & 2 deletions util/gvalid/internal/builtin/builtin_phone_loose.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import (
)

// RulePhoneLoose implements `phone-loose` rule:
// Loose mobile phone number verification(宽松的手机号验证)
// Loose mobile phone number verification.
// As long as the 11 digits numbers beginning with
// 13, 14, 15, 16, 17, 18, 19 can pass the verification
// (只要满足 13、14、15、16、17、18、19开头的11位数字都可以通过验证).
// (Any 11-digit numbers starting with 13, 14, 15, 16, 17, 18, 19 can pass the validation).
//
// Format: phone-loose
type RulePhoneLoose struct{}
Expand Down
26 changes: 13 additions & 13 deletions util/gvalid/internal/builtin/builtin_resident_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,23 @@ func (r RuleResidentId) Run(in RunInput) error {

// checkResidentId checks whether given id a china resident id number.
//
// xxxxxx yyyy MM dd 375 0 十八位
// xxxxxx yy MM dd 75 0 十五位
// xxxxxx yyyy MM dd 375 0 18 digits
// xxxxxx yy MM dd 75 0 15 digits
//
// 地区: [1-9]\d{5}
// 年的前两位:(18|19|([23]\d)) 1800-2399
// 年的后两位:\d{2}
// 月份: ((0[1-9])|(10|11|12))
// 天数: (([0-2][1-9])|10|20|30|31) 闰年不能禁止29+
// Region: [1-9]\d{5}
// First two digits of year: (18|19|([23]\d)) 1800-2399
// Last two digits of year: \d{2}
// Month: ((0[1-9])|(10|11|12))
// Day: (([0-2][1-9])|10|20|30|31) Leap year cannot prohibit 29+
//
// 三位顺序码:\d{3}
// 两位顺序码:\d{2}
// 校验码: [0-9Xx]
// Three sequential digits: \d{3}
// Two sequential digits: \d{2}
// Check code: [0-9Xx]
//
// 十八位:^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$
// 十五位:^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}$
// 18 digits: ^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$
// 15 digits: ^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}$
//
// 总:
// Total:
// (^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}$)
func (r RuleResidentId) checkResidentId(id string) bool {
id = strings.ToUpper(strings.TrimSpace(id))
Expand Down
Loading