2018-01-04 18:04:11 +08:00
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
2019-02-02 16:18:25 +08:00
|
|
|
|
"github.com/gogf/gf/g"
|
|
|
|
|
"github.com/gogf/gf/g/util/gvalid"
|
2018-01-04 18:04:11 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
//rule := "length:6,16"
|
|
|
|
|
//if m := gvalid.Check("123456", rule, nil); m != nil {
|
|
|
|
|
// fmt.Println(m)
|
|
|
|
|
//}
|
|
|
|
|
//if m := gvalid.Check("12345", rule, nil); m != nil {
|
|
|
|
|
// fmt.Println(m)
|
|
|
|
|
// // map[length:字段长度为6到16个字符]
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
//rule := "integer|between:6,16"
|
|
|
|
|
//msgs := "请输入一个整数|参数大小不对啊老铁"
|
|
|
|
|
//fmt.Println(gvalid.Check("5.66", rule, msgs))
|
|
|
|
|
//// map[integer:请输入一个整数 between:参数大小不对啊老铁]
|
|
|
|
|
|
|
|
|
|
//// 参数长度至少为6个数字或者6个字母,但是总长度不能超过16个字符
|
|
|
|
|
//rule := `regex:\d{6,}|\D{6,}|max-length:16`
|
|
|
|
|
//if m := gvalid.Check("123456", rule, nil); m != nil {
|
|
|
|
|
// fmt.Println(m)
|
|
|
|
|
//}
|
|
|
|
|
//if m := gvalid.Check("abcde6", rule, nil); m != nil {
|
|
|
|
|
// fmt.Println(m)
|
|
|
|
|
// // map[regex:字段值不合法]
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
//params := map[string]string {
|
|
|
|
|
// "passport" : "john",
|
|
|
|
|
// "password" : "123456",
|
|
|
|
|
// "password2" : "1234567",
|
|
|
|
|
//}
|
|
|
|
|
//rules := map[string]string {
|
|
|
|
|
// "passport" : "required|length:6,16",
|
|
|
|
|
// "password" : "required|length:6,16|same:password2",
|
|
|
|
|
// "password2" : "required|length:6,16",
|
|
|
|
|
//}
|
|
|
|
|
//fmt.Println(gvalid.CheckMap(params, rules))
|
|
|
|
|
//// map[passport:map[length:字段长度为6到16个字符] password:map[same:字段值不合法]]
|
|
|
|
|
|
2018-04-17 14:20:02 +08:00
|
|
|
|
params := map[string]interface{} {
|
2018-01-04 18:04:11 +08:00
|
|
|
|
"passport" : "john",
|
|
|
|
|
"password" : "123456",
|
|
|
|
|
"password2" : "1234567",
|
|
|
|
|
}
|
|
|
|
|
rules := map[string]string {
|
|
|
|
|
"passport" : "required|length:6,16",
|
|
|
|
|
"password" : "required|length:6,16|same:password2",
|
|
|
|
|
"password2" : "required|length:6,16",
|
|
|
|
|
}
|
|
|
|
|
msgs := map[string]interface{} {
|
|
|
|
|
"passport" : "账号不能为空|账号长度应当在:min到:max之间",
|
|
|
|
|
"password" : map[string]string {
|
|
|
|
|
"required" : "密码不能为空",
|
|
|
|
|
"same" : "两次密码输入不相等",
|
|
|
|
|
},
|
|
|
|
|
}
|
2018-11-13 00:12:35 +08:00
|
|
|
|
if e := gvalid.CheckMap(params, rules, msgs); e != nil {
|
|
|
|
|
g.Dump(e.Maps())
|
|
|
|
|
}
|
2018-01-04 18:04:11 +08:00
|
|
|
|
// map[passport:map[length:账号长度应当在6到16之间] password:map[same:两次密码输入不相等]]
|
|
|
|
|
}
|