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

     1  package validatetpl
     2  
     3  import (
     4  	"regexp"
     5  )
     6  
     7  const (
     8  	InvalidPlateNoType  = "车牌号类型错误"
     9  	InvalidPlateNoValue = "无效的车牌号"
    10  )
    11  
    12  var (
    13  	plateNoRegexp = regexp.MustCompile(`^(京|津|沪|渝|蒙|新|藏|宁|桂|港|澳|黑|吉|辽|晋|冀|青|鲁|豫|苏|皖|浙|闽|赣|湘|鄂|粤|琼|甘|陕|贵|云|川)[A-Z][0-9A-Z]{4,5}[0-9A-Z挂港澳学警领试]$`)
    14  )
    15  
    16  func ValidatePlateNo(v interface{}) (bool, string) {
    17  	s, ok := v.(string)
    18  	if !ok {
    19  		return false, InvalidPlateNoType
    20  	}
    21  
    22  	if s != "" && !plateNoRegexp.MatchString(s) {
    23  		return false, InvalidPlateNoValue
    24  	}
    25  
    26  	return true, ""
    27  }