mirror of
https://github.com/astaxie/beego.git
synced 2025-07-09 12:00:19 +00:00
Support Match validate function for tag
This commit is contained in:
@ -283,12 +283,12 @@ func TestZipCode(t *testing.T) {
|
||||
func TestValid(t *testing.T) {
|
||||
type user struct {
|
||||
Id int
|
||||
Name string `valid:"Required"`
|
||||
Name string `valid:"Required;Match(/^(test)?\\w*@(/test/);com$/)"`
|
||||
Age int `valid:"Required;Range(1, 140)"`
|
||||
}
|
||||
valid := Validation{}
|
||||
|
||||
u := user{Name: "test", Age: 40}
|
||||
u := user{Name: "test@/test/;com", Age: 40}
|
||||
b, err := valid.Valid(u)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@ -297,7 +297,7 @@ func TestValid(t *testing.T) {
|
||||
t.Error("validation should be passed")
|
||||
}
|
||||
|
||||
uptr := &user{Name: "test", Age: 180}
|
||||
uptr := &user{Name: "test", Age: 40}
|
||||
b, err = valid.Valid(uptr)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@ -305,4 +305,13 @@ func TestValid(t *testing.T) {
|
||||
if b {
|
||||
t.Error("validation should not be passed")
|
||||
}
|
||||
|
||||
u = user{Name: "test@/test/;com", Age: 180}
|
||||
b, err = valid.Valid(u)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if b {
|
||||
t.Error("validation should not be passed")
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user