github.com/qichengzx/mattermost-server@v4.5.1-0.20180604164826-2c75247c97d0+incompatible/plugin/valid.go (about)

     1  // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
     2  // See License.txt for license information.
     3  
     4  package plugin
     5  
     6  import (
     7  	"regexp"
     8  	"unicode/utf8"
     9  )
    10  
    11  const (
    12  	MinIdLength = 3
    13  	MaxIdLength = 190
    14  )
    15  
    16  var ValidId *regexp.Regexp
    17  
    18  func init() {
    19  	ValidId = regexp.MustCompile(`^[a-zA-Z0-9-_\.]+$`)
    20  }
    21  
    22  func IsValidId(id string) bool {
    23  	if utf8.RuneCountInString(id) < MinIdLength {
    24  		return false
    25  	}
    26  
    27  	if utf8.RuneCountInString(id) > MaxIdLength {
    28  		return false
    29  	}
    30  
    31  	return ValidId.MatchString(id)
    32  }