feat: initial commit
This commit is contained in:
27
internal/http/form/match_regexp.go
Normal file
27
internal/http/form/match_regexp.go
Normal file
@ -0,0 +1,27 @@
|
||||
package form
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func MatchRegExp(pattern string, message string) func(f *Field) error {
|
||||
return func(f *Field) error {
|
||||
value, err := FieldAttr[string](f, "value")
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
matches, err := regexp.MatchString(pattern, value)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
if !matches {
|
||||
return NewValidationError(message)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user