-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring.go
More file actions
39 lines (33 loc) · 689 Bytes
/
Copy pathstring.go
File metadata and controls
39 lines (33 loc) · 689 Bytes
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
package types
import "regexp"
type String string
func NewString(v string) String {
return String(v)
}
func (p String) Val() string {
return string(p)
}
func (p String) IsEmail() bool {
matchFlag := p.IsMatchAnyRegexp(
`^[\w]+(\.[\w]+)*@[\w]+(\.[\w])+$`,
`[\w]+(\.[\w]+)*@[\w]+(\.[\w])+`,
)
return matchFlag
}
func (p String) IsMatchAnyRegexp(patterns ...string) bool {
isMatch := func(pattern string) bool {
reg := regexp.MustCompile(pattern)
matchFlag := reg.MatchString(p.Val())
return matchFlag
}
if len(patterns) == 0 {
return false
}
for _, pattern := range patterns {
matchFlag := isMatch(pattern)
if matchFlag {
return true
}
}
return false
}