Merge pull request #123 from joeybloggs/v6-development

Add single Field validation example
pull/124/head
Dean Karn 9 years ago
commit f4625158e0
  1. 21
      README.md
  2. 19
      examples/simple.go

@ -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
@ -73,6 +73,12 @@ func main() {
validate = validator.New(config)
validateStruct()
validateField()
}
func validateStruct() {
address := &Address{
Street: "Eavesdown Docks",
Planet: "Persphone",
@ -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

@ -35,6 +35,12 @@ func main() {
validate = validator.New(config)
validateStruct()
validateField()
}
func validateStruct() {
address := &Address{
Street: "Eavesdown Docks",
Planet: "Persphone",
@ -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…
Cancel
Save