forked from hashicorp/terraform-provider-azurerm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
private_dns_zone_soa_record_email.go
41 lines (33 loc) · 1.06 KB
/
private_dns_zone_soa_record_email.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
41
package validate
import (
"fmt"
"regexp"
"strings"
)
func PrivateDnsZoneSOARecordEmail(v interface{}, k string) (warnings []string, errors []error) {
value := v.(string)
if len(value) == 0 {
errors = append(errors, fmt.Errorf("%q cannot be an empty string: %q", k, v))
return warnings, errors
}
vSegments := strings.Split(value, ".")
if len(vSegments) < 2 || len(vSegments) > 34 {
errors = append(errors, fmt.Errorf("%q must be between 2 and 34 segments", k))
return warnings, errors
}
for _, segment := range vSegments {
if segment == "" {
errors = append(errors, fmt.Errorf("%q cannot contain consecutive period", k))
return warnings, errors
}
if len(segment) > 63 {
errors = append(errors, fmt.Errorf("the each segment of the `email` must contain between 1 and 63 characters"))
return warnings, errors
}
}
if !regexp.MustCompile(`^[a-zA-Z\d._-]+$`).MatchString(value) {
errors = append(errors, fmt.Errorf("%q only contains letters, numbers, underscores, dashes and periods", k))
return warnings, errors
}
return warnings, errors
}