File: key.go

package info (click to toggle)
glab 1.53.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 20,936 kB
  • sloc: sh: 295; makefile: 153; perl: 99; ruby: 68; javascript: 67
file content (17 lines) | stat: -rw-r--r-- 526 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
package variableutils

import "regexp"

// IsValidKey checks if a key is valid if it follows the following criteria:
// must have no more than 255 characters;
// only A-Z, a-z, 0-9, and _ are allowed
func IsValidKey(key string) bool {
	// check if key falls within range of 1-255
	if len(key) > 255 || len(key) < 1 {
		return false
	}
	keyRE := regexp.MustCompile(`^[A-Za-z0-9_]+$`)
	return keyRE.MatchString(key)
}

var ValidKeyMsg = "A valid key must have no more than 255 characters; only A-Z, a-z, 0-9, and _ are allowed"