Created
December 21, 2015 07:32
-
-
Save netsharec/9538c00528946927fc1f to your computer and use it in GitHub Desktop.
检测是否合法的姓名
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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