Files
validate/uuid.go
T

23 lines
456 B
Go
Raw Normal View History

2023-10-06 11:58:24 +01:00
package validate
import (
"regexp"
)
2023-10-07 13:42:17 +01:00
var (
2023-11-19 20:42:48 +00:00
ErrInvalidUUID = NewError("invalid UUID")
2023-10-07 13:42:17 +01:00
)
2023-10-06 11:58:24 +01:00
var uuidRegexp = regexp.MustCompile("^[a-f0-9]{8}(-[a-f0-9]{4}){3}-[a-f0-9]{12}$")
2026-09-07 13:59:59 +01:00
// UUID validates a UUID string in the canonical 8-4-4-4-12 hyphenated
// form. Only lowercase hexadecimal is accepted; the version and variant
// bits are not checked.
2023-10-06 11:58:24 +01:00
func UUID(value string) error {
if !uuidRegexp.MatchString(value) {
2023-10-07 13:42:17 +01:00
return ErrInvalidUUID
2023-10-06 11:58:24 +01:00
}
return nil
}