Files
photoprism/pkg/http/dns/label.go
2025-10-19 21:08:48 +02:00

17 lines
348 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package dns
import (
"regexp"
)
var labelRegex = regexp.MustCompile(`^[a-z0-9](?:[a-z0-9-]{0,30}[a-z0-9])?$`)
// IsLabel returns true if s is a valid DNS label per our rules: lowercase, [a-z0-9-], 132 chars, starts/ends alnum.
func IsLabel(s string) bool {
if s == "" || len(s) > 32 {
return false
}
return labelRegex.MatchString(s)
}