This repository has been archived by the owner on Dec 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestValidators.go
67 lines (54 loc) · 2.26 KB
/
TestValidators.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package ecms_go_inputfilter
import (
ecms_validator "github.com/extensible-cms/ecms-go-validator"
"regexp"
)
var (
Validators map[int]ecms_validator.Validator
)
const (
IdValidatorKey = iota
SlugValidatorKey
AliasValidatorKey
NameValidatorKey
DescriptionValidatorKey
NotEmptyValidatorKey
Last4SocialKey
EmailValidatorKey
DigitValidatorKey
)
func init() {
IdValidatorOps := ecms_validator.NewIntRangeValidatorOptions()
IdValidatorOps.Min = 1
IdValidatorOps.Max = 20
IdValidator := ecms_validator.IntRangeValidator(IdValidatorOps)
DescrLenValidatorOps := ecms_validator.NewIntRangeValidatorOptions()
DescrLenValidatorOps.Min = 1
DescrLenValidatorOps.Max = 2048
DescrLenValidator := ecms_validator.IntRangeValidator(DescrLenValidatorOps)
slugValidatorOps := ecms_validator.NewRegexValidatorOptions()
slugValidatorOps.Pattern = regexp.MustCompile("^[a-z][a-z_\\-\\d]{1,54}$i")
SlugValidator := ecms_validator.RegexValidator(slugValidatorOps)
nameValidatorOps := ecms_validator.NewRegexValidatorOptions()
nameValidatorOps.Pattern = regexp.MustCompile("^[a-z][a-z\\s'\"]{5,54}$i")
NameValidator := ecms_validator.RegexValidator(nameValidatorOps)
NotEmptyValidator := ecms_validator.NotEmptyValidator1()
last4SocialValidatorOps := ecms_validator.NewRegexValidatorOptions()
last4SocialValidatorOps.Pattern = regexp.MustCompile("^\\d{4}$")
Last4SocialValidator := ecms_validator.RegexValidator(last4SocialValidatorOps)
fakeEmailValidatorOps := ecms_validator.NewRegexValidatorOptions()
fakeEmailValidatorOps.Pattern = regexp.MustCompile("^[^@]{1,55}@[^@]{1,55}$")
FakeEmailValidator := ecms_validator.RegexValidator(fakeEmailValidatorOps)
DigitValidator := ecms_validator.DigitValidator1()
Validators = map[int]ecms_validator.Validator{
IdValidatorKey: IdValidator,
SlugValidatorKey: SlugValidator,
AliasValidatorKey: SlugValidator,
NameValidatorKey: NameValidator, // add name validator
DescriptionValidatorKey: DescrLenValidator, // add description/content validator
NotEmptyValidatorKey: NotEmptyValidator,
Last4SocialKey: Last4SocialValidator,
EmailValidatorKey: FakeEmailValidator, // over-simplified version of email validation (not for production!!!)
DigitValidatorKey: DigitValidator,
}
}