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

     1  package validatetpl
     2  
     3  import (
     4  	"regexp"
     5  )
     6  
     7  const (
     8  	InvalidBusinessLicenseType  = "营业执照号类型错误"
     9  	InvalidBusinessLicenseValue = "无效的营业执照号"
    10  )
    11  
    12  var (
    13  	business_license_regexp = regexp.MustCompile(`^\d{15}$`)
    14  )
    15  
    16  func ValidateBusinessLicense(v interface{}) (bool, string) {
    17  	s, ok := v.(string)
    18  	if !ok {
    19  		return false, InvalidBusinessLicenseType
    20  	}
    21  	if !business_license_regexp.MatchString(s) {
    22  		return false, InvalidBusinessLicenseValue
    23  	}
    24  	return true, ""
    25  }
    26  
    27  func ValidateBusinessLicenseOrEmpty(v interface{}) (bool, string) {
    28  	s, ok := v.(string)
    29  	if !ok {
    30  		return false, InvalidBusinessLicenseType
    31  	}
    32  	if s != "" && !business_license_regexp.MatchString(s) {
    33  		return false, InvalidBusinessLicenseValue
    34  	}
    35  	return true, ""
    36  }