summaryrefslogtreecommitdiffstats
path: root/plugin/valid.go
blob: 62c594a1ae325454c83591262ec8965c984ef8ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

package plugin

import (
	"regexp"
	"unicode/utf8"
)

const (
	MinIdLength = 3
	MaxIdLength = 190
)

var ValidId *regexp.Regexp

func init() {
	ValidId = regexp.MustCompile(`^[a-zA-Z0-9-_\.]+$`)
}

func IsValidId(id string) bool {
	if utf8.RuneCountInString(id) < MinIdLength {
		return false
	}

	if utf8.RuneCountInString(id) > MaxIdLength {
		return false
	}

	return ValidId.MatchString(id)
}