package utility import ( "encoding/json" "regexp" "strings" "unicode" ) func InterfaceToJsonString(obj interface{}) string { jsonBytes, err := json.Marshal(obj) if err == nil { return string(jsonBytes) } return "" } func IsMobile(mobile string) bool { mobile = strings.Replace(mobile, " ", "", -1) if ok := CheckPhoneIsOK(mobile); !ok { return false } result, _ := regexp.MatchString(`^(1[3|4|5|6|7|8|9][0-9]\d{4,8})$`, mobile) return result } func CheckPhoneIsOK(phone string) bool { if len(phone) != 11 { return false } isOK := true for _, r := range phone { if !unicode.IsDigit(r) { isOK = false break } } return isOK }