check.go 567 字节
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 25 26 27 28 29 30 31
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]
}
func ValidateName(name string) bool {
	if name == "" {
		return false
	}
	return strings.IndexFunc(name, f) == -1

}