fix validator

This commit is contained in:
2025-08-18 18:18:04 +08:00
parent 59b3d76f57
commit ecfe7a6fd6
3 changed files with 4 additions and 4 deletions

View File

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

View File

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

View File

@@ -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":