Skip to content

Instantly share code, notes, and snippets.

@netsharec
Created December 21, 2015 07:32
Show Gist options
  • Save netsharec/9538c00528946927fc1f to your computer and use it in GitHub Desktop.
Save netsharec/9538c00528946927fc1f to your computer and use it in GitHub Desktop.
检测是否合法的姓名
import (
"unicode"
"unicode/utf8"
)
func VaildName(s string) bool {
l := utf8.RuneCountInString(s)
if l < 2 || l > 4 {
return false
}
for _, r := range []rune(s) {
if !unicode.Is(unicode.Scripts["Han"], r) {
return false
}
}
return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment