package main
import (
"fmt"
"regexp"
)
func IsEmail(s string) bool {
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}$`
reg := regexp.MustCompile(pattern)
return reg.MatchString(s)
}
func main() {
/*
匹配邮箱地址
*/
email := []string{"test01@163.com","test02@163.123", ".test03g@qq.com", "test04@gmail.com"}
for _, val := range email {
if is := IsEmail(val); is {
fmt.Printf("%s 是符合规定的邮件地址\n",val)
} else {
fmt.Printf("%s 不符合要求\n",val)
}
}
}