Skip to content

Commit

Permalink
Merge pull request #1114 from torden/feature/add-validation
Browse files Browse the repository at this point in the history
Improve Validation API
  • Loading branch information
notzippy committed Jul 12, 2017
2 parents caf6730 + a78ac94 commit 41c8d85
Show file tree
Hide file tree
Showing 3 changed files with 764 additions and 1 deletion.
24 changes: 24 additions & 0 deletions validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,30 @@ func (v *Validation) Email(str string) *ValidationResult {
return v.apply(Email{Match{emailPattern}}, str)
}

func (v *Validation) IPAddr(str string, cktype ...int) *ValidationResult {
return v.apply(IPAddr{cktype}, str)
}

func (v *Validation) MacAddr(str string) *ValidationResult {
return v.apply(IPAddr{}, str)
}

func (v *Validation) Domain(str string) *ValidationResult {
return v.apply(Domain{}, str)
}

func (v *Validation) URL(str string) *ValidationResult {
return v.apply(URL{}, str)
}

func (v *Validation) PureText(str string, m int) *ValidationResult {
return v.apply(PureText{m}, str)
}

func (v *Validation) FilePath(str string, m int) *ValidationResult {
return v.apply(FilePath{m}, str)
}

func (v *Validation) apply(chk Validator, obj interface{}) *ValidationResult {
if chk.IsSatisfied(obj) {
return &ValidationResult{Ok: true}
Expand Down

0 comments on commit 41c8d85

Please sign in to comment.