check.go 608 字节
Newer Older
E
eoLinker API Management 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
package service

import "strings"

//var nameLetters ="abcdefghijklmnopqrstuvwxyz_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
var nameLetters map[rune]bool

func init() {
	nameLetters = make(map[rune]bool)
	nameLetters['_'] = true
	for r := 'A'; r <= 'Z'; r++ {
		nameLetters[r] = true
	}
	for r := 'a'; r <= 'z'; r++ {
		nameLetters[r] = true
	}
	for r := '0'; r <= '9'; r++ {
		nameLetters[r] = true
	}
}

func f(r rune) bool {
	return !nameLetters[r]
}
Y
Your Name 已提交
25 26

//ValidateName 判断名称是否合法
E
eoLinker API Management 已提交
27 28 29 30 31 32 33
func ValidateName(name string) bool {
	if name == "" {
		return false
	}
	return strings.IndexFunc(name, f) == -1

}