github.com/profzone/eden-framework@v1.0.10/pkg/validate/validatetpl/org_insititute_code.go (about)

     1  package validatetpl
     2  
     3  import (
     4  	"regexp"
     5  )
     6  
     7  const (
     8  	InvalidOrgInsitituteCodeType  = "组织机构代码类型错误"
     9  	InvalidOrgInsitituteCodeValue = "无效的组织机构代码"
    10  )
    11  
    12  var (
    13  	org_insititute_code_regexp = regexp.MustCompile(`^\w{8}-\w$`)
    14  )
    15  
    16  func ValidateOrgInsitituteCode(v interface{}) (bool, string) {
    17  	s, ok := v.(string)
    18  	if !ok {
    19  		return false, InvalidOrgInsitituteCodeType
    20  	}
    21  	if !org_insititute_code_regexp.MatchString(s) {
    22  		return false, InvalidOrgInsitituteCodeValue
    23  	}
    24  	return true, ""
    25  }
    26  
    27  func ValidateOrgInsitituteCodeOrEmpty(v interface{}) (bool, string) {
    28  	s, ok := v.(string)
    29  	if !ok {
    30  		return false, InvalidOrgInsitituteCodeType
    31  	}
    32  	if s != "" && !org_insititute_code_regexp.MatchString(s) {
    33  		return false, InvalidOrgInsitituteCodeValue
    34  	}
    35  	return true, ""
    36  }