plugins/utils/helper/common.go

31 lines
746 B
Go

package helper
import (
"golang.org/x/text/encoding/simplifiedchinese"
"golang.org/x/text/transform"
"os"
"regexp"
)
func FileExists(filePath string) bool {
_, err := os.Stat(filePath)
return err == nil || os.IsExist(err)
}
// ToChinese 处理文件名编码为简体中文
func ToChinese(s string) string {
encoder := simplifiedchinese.GBK.NewDecoder()
encodedName, _, _ := transform.String(encoder, s)
return encodedName
}
func IsPhoneNumber(phoneNumber string) bool {
phoneRegex := `^1[34578]\d{9}$`
return regexp.MustCompile(phoneRegex).MatchString(phoneNumber)
}
func IsEmail(email string) bool {
var emailRegex = regexp.MustCompile(`[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$`)
return emailRegex.MatchString(email)
}