|
|
|
@ -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 { |
|
|
|
|