1
0
mirror of https://github.com/astaxie/beego.git synced 2025-07-10 02:40:17 +00:00

Support Match validate function for tag

This commit is contained in:
miraclesu
2013-07-28 19:22:09 +08:00
parent dcdfaf36f1
commit 6662eef2fd
4 changed files with 67 additions and 18 deletions

View File

@ -6,10 +6,11 @@ import (
)
type user struct {
Id int
Tag string `valid:"Maxx(aa)"`
Name string `valid:"Required"`
Age int `valid:"Required;Range(1, 140)"`
Id int
Tag string `valid:"Maxx(aa)"`
Name string `valid:"Required;"`
Age int `valid:"Required;Range(1, 140)"`
match string `valid:"Required; Match(/^(test)?\\w*@(/test/);com$/);Max(2)"`
}
func TestGetValidFuncs(t *testing.T) {
@ -55,6 +56,14 @@ func TestGetValidFuncs(t *testing.T) {
if vfs[1].Name != "Range" && len(vfs[1].Params) != 2 {
t.Error("Range funcs should be got")
}
f, _ = tf.FieldByName("match")
if vfs, err = getValidFuncs(f); err != nil {
t.Fatal(err)
}
if len(vfs) != 3 {
t.Fatal("should get 3 ValidFunc but now is", len(vfs))
}
}
func TestCall(t *testing.T) {