1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- package common
- import (
- "strings"
- )
- const (
- OPER_CODE_PREFIX = "OPER_"
- ORGAN_CODE_PREFIX = "ORGAN_"
- OPER_CODE_PREFIX_LEN = len(OPER_CODE_PREFIX)
- )
- func EncodeOperAccount(account string) string {
- return OPER_CODE_PREFIX + account
- }
- func EncodeOrganAccount(account string) string {
- return ORGAN_CODE_PREFIX + account
- }
- func DecodeOperAccount(account string) string {
- return account[OPER_CODE_PREFIX_LEN:]
- }
- func GetAccountPrefix(account string) string {
- i := strings.IndexAny(account, "_")
- if i == -1 {
- return ""
- }
- return account[0 : i+1]
- }
- func DecodeAccount(account string) string {
- i := strings.IndexAny(account, "_")
- if i == -1 {
- return ""
- }
- return account[i+1:]
- }
- //4-22字符,只允许小写字母、数字、下划线,且首位须为字母
- func CheckAccountFormat(account string) bool {
- len := strings.Count(account, "") - 1
- if len < 4 || len > 22 {
- return false
- }
- for i, _ := range account {
- if i == 0 {
- if !(account[0:1] >= "a" && account[0:1] <= "z") {
- return false
- }
- } else {
- if (account[i:i+1] >= "0" && account[i:i+1] <= "9") ||
- (account[i:i+1] >= "a" && account[i:i+1] <= "z") ||
- account[i:i+1] == "_" {
- continue
- } else {
- return false
- }
- }
- }
- return true
- }
|