diff options
Diffstat (limited to 'modules/middleware/binding.go')
-rw-r--r-- | modules/middleware/binding.go | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/modules/middleware/binding.go b/modules/middleware/binding.go index cde9ae9cc0..bff34ddde0 100644 --- a/modules/middleware/binding.go +++ b/modules/middleware/binding.go @@ -180,9 +180,10 @@ func Validate(obj interface{}) martini.Handler { } var ( - alphaDashPattern = regexp.MustCompile("[^\\d\\w-_]") - emailPattern = regexp.MustCompile("[\\w!#$%&'*+/=?^_`{|}~-]+(?:\\.[\\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\\w](?:[\\w-]*[\\w])?\\.)+[a-zA-Z0-9](?:[\\w-]*[\\w])?") - urlPattern = regexp.MustCompile(`(http|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?`) + alphaDashPattern = regexp.MustCompile("[^\\d\\w-_]") + alphaDashDotPattern = regexp.MustCompile("[^\\d\\w-_\\.]") + emailPattern = regexp.MustCompile("[\\w!#$%&'*+/=?^_`{|}~-]+(?:\\.[\\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\\w](?:[\\w-]*[\\w])?\\.)+[a-zA-Z0-9](?:[\\w-]*[\\w])?") + urlPattern = regexp.MustCompile(`(http|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?`) ) func validateStruct(errors *base.BindingErrors, obj interface{}) { @@ -227,6 +228,11 @@ func validateStruct(errors *base.BindingErrors, obj interface{}) { errors.Fields[field.Name] = base.BindingAlphaDashError break } + case rule == "AlphaDashDot": + if alphaDashDotPattern.MatchString(fmt.Sprintf("%v", fieldValue)) { + errors.Fields[field.Name] = base.BindingAlphaDashDotError + break + } case strings.HasPrefix(rule, "MinSize("): min, err := strconv.Atoi(rule[8 : len(rule)-1]) if err != nil { |