...
1
9
10 package validate
11
12 import (
13 "fmt"
14 "regexp"
15 )
16
17 func (options *Options) ValidEmail() error {
18 if !options.Required && options.ValueText == "" {
19 return nil
20 }
21
22 regexPattern := "^[a-zA-Z0-9.-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$"
23
24 regex, err := regexp.Compile(regexPattern)
25 if err != nil {
26 return err
27 }
28
29 isValid := regex.MatchString(options.ValueText)
30 if !isValid {
31 return fmt.Errorf("invalid type email: Email must be valid")
32 }
33
34 return nil
35 }
36
View as plain text