1234567891011121314151617181920212223242526272829303132333435 |
- package utils
- import (
- "fmt"
- "regexp"
- "unsafe"
- "encoding/json"
- )
- // StrToBytes 快读的string转byte
- func StrToBytes(s string) []byte {
- x := (*[2]uintptr)(unsafe.Pointer(&s))
- h := [3]uintptr{x[0], x[1], x[1]}
- return *(*[]byte)(unsafe.Pointer(&h))
- }
- func PrintStruct(prefix string, data interface{}) {
- bytes, _ := json.Marshal(data)
- fmt.Printf("%s, %s\n", prefix, bytes)
- }
- func VerifyEmailFormat(email string) bool {
- pattern := `\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*` //匹配电子邮箱
- reg := regexp.MustCompile(pattern)
- return reg.MatchString(email)
- }
- func VerifyMobileFormat(phone string) bool {
- regular := "^((13[0-9])|(14[5,7])|(15[0-3,5-9])|(17[0,3,5-8])|(18[0-9])|166|198|199|(147))\\d{8}$"
- reg := regexp.MustCompile(regular)
- return reg.MatchString(phone)
- }
|