20 lines
359 B
Go
20 lines
359 B
Go
package domainutils
|
|
|
|
import (
|
|
"regexp"
|
|
"strings"
|
|
)
|
|
|
|
// ValidateDomainFormat 校验域名格式
|
|
func ValidateDomainFormat(domain string) bool {
|
|
pieces := strings.Split(domain, ".")
|
|
for _, piece := range pieces {
|
|
// \p{Han} 中文unicode字符集
|
|
if !regexp.MustCompile(`^[\p{Han}a-z0-9-]+$`).MatchString(piece) {
|
|
return false
|
|
}
|
|
}
|
|
|
|
return true
|
|
}
|