-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidation.go
37 lines (29 loc) · 1 KB
/
validation.go
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
33
34
35
36
37
package webhookrelay
import (
"errors"
"regexp"
)
const (
// IDFormat are the characters allowed to represent an ID.
IDFormat = `[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}`
// NameFormat are the characters allowed to represent a name.
NameFormat = `[a-zA-Z0-9][a-zA-Z0-9~_.-]+`
)
var (
// IDPattern is a regular expression to validate a unique id against the
// collection of restricted characters.
IDPattern = regexp.MustCompile(`^` + IDFormat + `$`)
// NamePattern is a regular expression to validate names against the
// collection of restricted characters.
NamePattern = regexp.MustCompile(`^` + NameFormat + `$`)
// ErrNoRef returned when ref is incorrect
ErrNoRef = errors.New("no ref provided or incorrect format")
)
// IsUUID returns true if the string input is a valid UUID string.
func IsUUID(s string) bool {
return IDPattern.MatchString(s)
}
// IsName returns true if the string input is a valid Name string.
func IsName(s string) bool {
return NamePattern.MatchString(s)
}