fix validator
This commit is contained in:
@@ -137,9 +137,9 @@ func (bv *BusinessValidator) ValidateProductCode(code string) error {
|
||||
if code == "" {
|
||||
return fmt.Errorf("产品代码不能为空")
|
||||
}
|
||||
matched, _ := regexp.MatchString(`^[a-zA-Z0-9_-]{3,50}$`, code)
|
||||
matched, _ := regexp.MatchString(`^[a-zA-Z0-9_\-\(\)()]{3,50}$`, code)
|
||||
if !matched {
|
||||
return fmt.Errorf("产品代码格式不正确,只能包含字母、数字、下划线、连字符,长度3-50位")
|
||||
return fmt.Errorf("产品代码格式不正确,只能包含字母、数字、下划线、连字符、中英文括号,长度3-50位")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ func registerCustomFieldTranslations(validate *validator.Validate, trans ut.Tran
|
||||
|
||||
// 产品代码翻译
|
||||
validate.RegisterTranslation("product_code", trans, func(ut ut.Translator) error {
|
||||
return ut.Add("product_code", "{0}格式不正确,只能包含字母、数字、下划线、连字符,长度3-50位", true)
|
||||
return ut.Add("product_code", "{0}格式不正确,只能包含字母、数字、下划线、连字符、中英文括号,长度3-50位", true)
|
||||
}, func(ut ut.Translator, fe validator.FieldError) string {
|
||||
t, _ := ut.T("product_code", getFieldDisplayName(fe.Field()))
|
||||
return t
|
||||
|
||||
@@ -168,7 +168,7 @@ func (v *RequestValidator) getFallbackErrorMessage(fieldError validator.FieldErr
|
||||
case "sort_order":
|
||||
return fmt.Sprintf("%s必须是 asc 或 desc", fieldDisplayName)
|
||||
case "product_code":
|
||||
return fmt.Sprintf("%s格式不正确,只能包含字母、数字、下划线、连字符,长度3-50位", fieldDisplayName)
|
||||
return fmt.Sprintf("%s格式不正确,只能包含字母、数字、下划线、连字符、中英文括号,长度3-50位", fieldDisplayName)
|
||||
case "uuid":
|
||||
return fmt.Sprintf("%s必须是有效的UUID格式", fieldDisplayName)
|
||||
case "url":
|
||||
|
||||
Reference in New Issue
Block a user