|
|
@ -5,7 +5,9 @@ |
|
|
|
package form |
|
|
|
package form |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
|
|
|
|
"fmt" |
|
|
|
"reflect" |
|
|
|
"reflect" |
|
|
|
|
|
|
|
"regexp" |
|
|
|
"strings" |
|
|
|
"strings" |
|
|
|
|
|
|
|
|
|
|
|
"github.com/Unknwon/com" |
|
|
|
"github.com/Unknwon/com" |
|
|
@ -13,8 +15,24 @@ import ( |
|
|
|
"gopkg.in/macaron.v1" |
|
|
|
"gopkg.in/macaron.v1" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const ERR_ALPHA_DASH_DOT_SLASH = "AlphaDashDotSlashError" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var AlphaDashDotSlashPattern = regexp.MustCompile("[^\\d\\w-_\\./]") |
|
|
|
|
|
|
|
|
|
|
|
func init() { |
|
|
|
func init() { |
|
|
|
binding.SetNameMapper(com.ToSnakeCase) |
|
|
|
binding.SetNameMapper(com.ToSnakeCase) |
|
|
|
|
|
|
|
binding.AddRule(&binding.Rule{ |
|
|
|
|
|
|
|
IsMatch: func(rule string) bool { |
|
|
|
|
|
|
|
return rule == "AlphaDashDotSlash" |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
IsValid: func(errs binding.Errors, name string, v interface{}) (bool, binding.Errors) { |
|
|
|
|
|
|
|
if AlphaDashDotSlashPattern.MatchString(fmt.Sprintf("%v", v)) { |
|
|
|
|
|
|
|
errs.Add([]string{name}, ERR_ALPHA_DASH_DOT_SLASH, "AlphaDashDotSlash") |
|
|
|
|
|
|
|
return false, errs |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return true, errs |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type Form interface { |
|
|
|
type Form interface { |
|
|
@ -113,6 +131,8 @@ func validate(errs binding.Errors, data map[string]interface{}, f Form, l macaro |
|
|
|
data["ErrorMsg"] = trName + l.Tr("form.alpha_dash_error") |
|
|
|
data["ErrorMsg"] = trName + l.Tr("form.alpha_dash_error") |
|
|
|
case binding.ERR_ALPHA_DASH_DOT: |
|
|
|
case binding.ERR_ALPHA_DASH_DOT: |
|
|
|
data["ErrorMsg"] = trName + l.Tr("form.alpha_dash_dot_error") |
|
|
|
data["ErrorMsg"] = trName + l.Tr("form.alpha_dash_dot_error") |
|
|
|
|
|
|
|
case ERR_ALPHA_DASH_DOT_SLASH: |
|
|
|
|
|
|
|
data["ErrorMsg"] = trName + l.Tr("form.alpha_dash_dot_slash_error") |
|
|
|
case binding.ERR_SIZE: |
|
|
|
case binding.ERR_SIZE: |
|
|
|
data["ErrorMsg"] = trName + l.Tr("form.size_error", getSize(field)) |
|
|
|
data["ErrorMsg"] = trName + l.Tr("form.size_error", getSize(field)) |
|
|
|
case binding.ERR_MIN_SIZE: |
|
|
|
case binding.ERR_MIN_SIZE: |
|
|
|