mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-02-03 22:18:39 +00:00
15 lines
506 B
Go
15 lines
506 B
Go
package cli
|
|
|
|
import "regexp"
|
|
|
|
// validHostname reports whether hostname is a valid hostname.
|
|
// A valid hostname contains 3 -> 64 characters and conform to RFC1123.
|
|
func validHostname(hostname string) bool {
|
|
hostnameLen := len(hostname)
|
|
if hostnameLen < 3 || hostnameLen > 64 {
|
|
return false
|
|
}
|
|
validHostnameRfc1123 := regexp.MustCompile(`^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$`)
|
|
return validHostnameRfc1123.MatchString(hostname)
|
|
}
|