mirror of
https://github.com/directorz/mailfull-go.git
synced 2025-12-20 02:57:06 +00:00
Implement some parts for loading data from a directory
This commit is contained in:
52
valid.go
Normal file
52
valid.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package mailfull
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
// Errors for incorrect format.
|
||||
var (
|
||||
ErrInvalidDomainName = errors.New("Domain: name incorrect format")
|
||||
ErrInvalidAliasDomainName = errors.New("AliasDomain: name incorrect format")
|
||||
ErrInvalidAliasDomainTarget = errors.New("AliasDomain: target incorrect format")
|
||||
ErrInvalidUserName = errors.New("User: name incorrect format")
|
||||
ErrInvalidAliasUserName = errors.New("AliasUser: name incorrect format")
|
||||
ErrInvalidAliasUserTarget = errors.New("AliasUser: target incorrect format")
|
||||
ErrInvalidCatchAllUserName = errors.New("CatchAllUser: name incorrect format")
|
||||
)
|
||||
|
||||
// validDomainName returns true if the input is correct format.
|
||||
func validDomainName(name string) bool {
|
||||
return regexp.MustCompile(`^([A-Za-z0-9][A-Za-z0-9\-]{1,61}[A-Za-z0-9]\.)*[A-Za-z]+$`).MatchString(name)
|
||||
}
|
||||
|
||||
// validAliasDomainName returns true if the input is correct format.
|
||||
func validAliasDomainName(name string) bool {
|
||||
return regexp.MustCompile(`^([A-Za-z0-9][A-Za-z0-9\-]{1,61}[A-Za-z0-9]\.)*[A-Za-z]+$`).MatchString(name)
|
||||
}
|
||||
|
||||
// validAliasDomainTarget returns true if the input is correct format.
|
||||
func validAliasDomainTarget(target string) bool {
|
||||
return regexp.MustCompile(`^([A-Za-z0-9][A-Za-z0-9\-]{1,61}[A-Za-z0-9]\.)*[A-Za-z]+$`).MatchString(target)
|
||||
}
|
||||
|
||||
// validUserName returns true if the input is correct format.
|
||||
func validUserName(name string) bool {
|
||||
return regexp.MustCompile(`^[^\s]+$`).MatchString(name)
|
||||
}
|
||||
|
||||
// validAliasUserName returns true if the input is correct format.
|
||||
func validAliasUserName(name string) bool {
|
||||
return regexp.MustCompile(`^[^\s]+$`).MatchString(name)
|
||||
}
|
||||
|
||||
// validAliasUserTarget returns true if the input is correct format.
|
||||
func validAliasUserTarget(target string) bool {
|
||||
return regexp.MustCompile(`^[^\s]+@([A-Za-z0-9][A-Za-z0-9\-]{1,61}[A-Za-z0-9]\.)*[A-Za-z]+$`).MatchString(target)
|
||||
}
|
||||
|
||||
// validCatchAllUserName returns true if the input is correct format.
|
||||
func validCatchAllUserName(name string) bool {
|
||||
return regexp.MustCompile(`^[^\s]+$`).MatchString(name)
|
||||
}
|
||||
Reference in New Issue
Block a user