1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- package domainservice
- import (
- "context"
- "mime/multipart"
- "regexp"
- "strings"
- "Cold_Logistic/internal/pkg/common/codex"
- "github.com/dlclark/regexp2"
- validation "github.com/go-ozzo/ozzo-validation/v4"
- "gogs.baozhida.cn/Cold_Logistic_libs/pkg/contrib/errors"
- )
- func ValidationAccountNum() validation.RuleWithContextFunc {
- return func(ctx context.Context, value interface{}) error {
- reg, err := regexp2.Compile(`^((?=.*[0-9])(?=.*[a-zA-Z]).{6,50})$`, 0)
- if err != nil {
- return err
- }
- m, err := reg.MatchString(value.(string))
- if err != nil {
- return err
- }
- if !m {
- return errors.New("可以是手机号码或者包含字符和数字,至少6位")
- }
- return nil
- }
- }
- func ValidationIdentityNumber() validation.RuleWithContextFunc {
- return func(ctx context.Context, value interface{}) error {
- regx := "((^[1-9][0-9]{5}(18|19|20)[0-9]{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)[0-9]{3}([0-9]|(X|x)))|(^[1-9][0-9]{5}[0-9]{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)[0-9]{2}[0-9]))"
- err := validation.Validate(value, validation.Match(regexp.MustCompile(regx)).Error("身份证号码不合规"))
- if err != nil {
- return err
- }
- return nil
- }
- }
- func ValidationExcelFile(fileHeader *multipart.FileHeader, limitSize int64) error {
- if !strings.HasSuffix(fileHeader.Filename, "xlsx") {
- return errors.WithCode(codex.ErrParamValidate, "文件扩展名必须是xlsx")
- }
- if fileHeader.Size > limitSize {
- return errors.WithCode(codex.ErrParamValidate, "文件大小不能超过10M")
- }
- return nil
- }
|