golang正则验证邮箱格式

 1 func VerifyEmailFormat(email string) bool {
 2     pattern := `\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*` //匹配电子邮箱
 3     reg := regexp.MustCompile(pattern)
 4     return reg.MatchString(email)
 5 }
 6 
 7 func main() {
 8     fmt.Println(VerifyEmailFormat("12345@126.com")) //true
 9     fmt.Println(VerifyEmailFormat("12345126.com"))  //false
10 }

 

posted @ 2018-12-05 18:02  追逐~~~  阅读(6781)  评论(0编辑  收藏  举报