Add email not blacklisted validator
Signed-off-by: Émile Ré <nemile.re@gmail.com>
This commit is contained in:
@@ -1 +1,47 @@
|
||||
package validator
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
//go:embed data/disposable-email-domains/disposable_email_blocklist.conf
|
||||
disposableEmailsRaw []byte
|
||||
testEmails = []string{
|
||||
"acme.com",
|
||||
"acme.net",
|
||||
"acme.org",
|
||||
"ethereal.email",
|
||||
"example.com",
|
||||
"example.net",
|
||||
"example.org",
|
||||
"mailhog.local",
|
||||
"mailslurp.com",
|
||||
"test.com",
|
||||
"test.net",
|
||||
"test.org",
|
||||
"localhost.localdomain",
|
||||
}
|
||||
blacklistedEmails = append(
|
||||
strings.Split(strings.TrimSpace(string(disposableEmailsRaw)), "\n"),
|
||||
testEmails...,
|
||||
)
|
||||
)
|
||||
|
||||
func NotBlacklisted() ValidatorFunc {
|
||||
notOneOfSlice := NotOneOfSlice(blacklistedEmails)
|
||||
|
||||
return func(value any) *ValidationError {
|
||||
err := notOneOfSlice(value)
|
||||
|
||||
if err == nil {
|
||||
return newValidationError(
|
||||
ErrorCodeInvalidEnum,
|
||||
"must not be blacklisted",
|
||||
)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
emailRegex = regexp.MustCompile(`^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$`)
|
||||
uuidRegex = regexp.MustCompile(`^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$`)
|
||||
domainRegex = regexp.MustCompile(`^(?:[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])?$`)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user