fix email regex rule

This commit is contained in:
shiw
2023-08-11 17:58:22 +08:00
parent 7fcf8fb73c
commit 927f44c6a5
4 changed files with 16 additions and 2 deletions

View File

@@ -89,8 +89,8 @@ func IsMobile(mobile string) bool {
// IsEmail 是否为邮箱地址
func IsEmail(email string) bool {
// pattern := `\w+([-+.]\w+)@\w+([-.]\w+).\w+([-.]\w+)*` //匹配电子邮箱
pattern := `^[0-9a-z][_.0-9a-z-]{0,31}@([0-9a-z][0-9a-z-]{0,30}[0-9a-z].){1,4}[a-z]{2,4}$`
// pattern := `^[0-9a-z][_.0-9a-z-]{0,31}@([0-9a-z][0-9a-z-]{0,30}[0-9a-z].){1,4}[a-z]{2,4}$` //匹配电子邮箱
pattern := `^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$`
reg := regexp.MustCompile(pattern)
return reg.MatchString(email)
}