-
Notifications
You must be signed in to change notification settings - Fork 0
/
re.go
40 lines (33 loc) · 768 Bytes
/
re.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package re
import (
"github.com/dlclark/regexp2"
"net/mail"
"regexp"
)
/*
File name : re.go
Author : miaoyc
Create date : 2022/10/31 14:21
Description :
*/
var mailReg *regexp.Regexp
var mailReg2 *regexp2.Regexp
func init() {
mailPattern := `^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$`
mailReg = regexp.MustCompile(mailPattern)
mailReg2, _ = regexp2.Compile(mailPattern, 0)
}
func ExampleParseAddress(email string) (string, string, error) {
e, err := mail.ParseAddress(email)
if err != nil {
return "", "", err
}
return e.Name, e.Address, nil
}
func VerifyEmailFormat(email string) bool {
return mailReg.MatchString(email)
}
func Reg2VerifyEmailFormat(email string) bool {
isMatch, _ := mailReg2.MatchString(email)
return isMatch
}