d23700b9 by miraclesu

update README

1 parent 92db56c0
...@@ -15,6 +15,8 @@ Test: ...@@ -15,6 +15,8 @@ Test:
15 15
16 ## Example 16 ## Example
17 17
18 Direct Use:
19
18 import ( 20 import (
19 "github.com/astaxie/beego/validation" 21 "github.com/astaxie/beego/validation"
20 "log" 22 "log"
...@@ -44,6 +46,53 @@ Test: ...@@ -44,6 +46,53 @@ Test:
44 } 46 }
45 } 47 }
46 48
49 Struct Tag Use:
50
51 import (
52 "github.com/astaxie/beego/validation"
53 )
54
55 // validation function follow with "valid" tag
56 // functions divide with ";"
57 // parameters in parentheses "()" and divide with ","
58 type user struct {
59 Id int
60 Name string `valid:"Required"`
61 Age int `valid:"Required;Range(1, 140)"`
62 }
63
64 func main() {
65 valid := Validation{}
66 u := user{Name: "test", Age: 40}
67 b, err := valid.Valid(u)
68 if err != nil {
69 // handle error
70 }
71 if !b {
72 // validation does not pass
73 // blabla...
74 }
75 }
76
77 Struct Tag Functions:
78
79 Required
80 Min(min int)
81 Max(max int)
82 Range(min, max int)
83 MinSize(min int)
84 MaxSize(max int)
85 Length(length int)
86 Alpha
87 Numeric
88 AlphaNumeric
89 Match(regexp string) // does not support yet
90 NoMatch(regexp string) // does not support yet
91 AlphaDash
92 Email
93 IP
94 Base64
95
47 96
48 ## LICENSE 97 ## LICENSE
49 98
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!