diff options
Diffstat (limited to 'plugin/valid.go')
-rw-r--r-- | plugin/valid.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/plugin/valid.go b/plugin/valid.go new file mode 100644 index 000000000..62c594a1a --- /dev/null +++ b/plugin/valid.go @@ -0,0 +1,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) +} |