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
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Usage and documentation

Please see http://godoc.org/gopkg.in/bluesuncorp/validator.v6 for detailed usage docs.

##### Example:
##### Examples:
```go
package main

Expand Down Expand Up @@ -73,6 +73,12 @@ func main() {

validate = validator.New(config)

validateStruct()
validateField()
}

func validateStruct() {

address := &Address{
Street: "Eavesdown Docks",
Planet: "Persphone",
Expand Down Expand Up @@ -109,6 +115,19 @@ func main() {

// save user to database
}

func validateField() {
myEmail := "joeybloggs.gmail.com"

errs := validate.Field(myEmail, "required,email")

if errs != nil {
fmt.Println(errs) // output: Key: "" Error:Field validation for "" failed on the "email" tag
return
}

// email ok, move on
}
```

Benchmarks
Expand Down
19 changes: 19 additions & 0 deletions examples/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ func main() {

validate = validator.New(config)

validateStruct()
validateField()
}

func validateStruct() {

address := &Address{
Street: "Eavesdown Docks",
Planet: "Persphone",
Expand Down Expand Up @@ -71,3 +77,16 @@ func main() {

// save user to database
}

func validateField() {
myEmail := "joeybloggs.gmail.com"

errs := validate.Field(myEmail, "required,email")

if errs != nil {
fmt.Println(errs) // output: Key: "" Error:Field validation for "" failed on the "email" tag
return
}

// email ok, move on
}
Loading