-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspec_string_ext.go
142 lines (137 loc) · 7.91 KB
/
spec_string_ext.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package vd
// ref: https://github.com/go-playground/validator/blob/059510c3bff4688135f150f0ed6e87d18539ca94/regexes.go
const (
// alphaRegexString = "^[a-zA-Z]+$"
// alphaNumericRegexString = "^[a-zA-Z0-9]+$"
// alphaUnicodeRegexString = "^[\\p{L}]+$"
// alphaUnicodeNumericRegexString = "^[\\p{L}\\p{N}]+$"
// numericRegexString = "^[-+]?[0-9]+(?:\\.[0-9]+)?$"
// numberRegexString = "^[0-9]+$"
hexRegexp = "^[0-9a-fA-F]+$"
hexcolorRegex = "^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$"
rgbRegex = "^rgb\\(\\s*(?:(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])|(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%)\\s*\\)$"
rgbaRegex = "^rgba\\(\\s*(?:(?:0|[1-9]\\d?|1\\d\\d?|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$"
// iSBN13Regex = "^(?:(?:97(?:8|9))[0-9]{10})$"
// uUID3Regex = "^[0-9a-f]{8}-[0-9a-f]{4}-3[0-9a-f]{3}-[0-9a-f]{4}-[0-9a-f]{12}$"
// uUID4Regex = "^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
// uUID5Regex = "^[0-9a-f]{8}-[0-9a-f]{4}-5[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
uUIDRegex = "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
// uUID3RFC4122Regex = "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-3[0-9a-fA-F]{3}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"
// uUID4RFC4122Regex = "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$"
// uUID5RFC4122Regex = "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-5[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$"
// uUIDRFC4122Regex = "^[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}$"
aSCIIRegex = "^[\x00-\x7F]*$"
printableASCIIRegex = "^[\x20-\x7E]*$"
// multibyteRegex = "[^\x00-\x7F]"
dataURIRegex = `^data:((?:\w+\/(?:([^;]|;[^;]).)+)?)`
latitudeRegex = "^[-+]?([1-8]?\\d(\\.\\d+)?|90(\\.0+)?)$"
longitudeRegex = "^[-+]?(180(\\.0+)?|((1[0-7]\\d)|([1-9]?\\d))(\\.\\d+)?)$"
// sSNRegex = `^[0-9]{3}[ -]?(0[1-9]|[1-9][0-9])[ -]?([1-9][0-9]{3}|[0-9][1-9][0-9]{2}|[0-9]{2}[1-9][0-9]|[0-9]{3}[1-9])$`
// hostnameRegexStringRFC952 = `^[a-zA-Z]([a-zA-Z0-9\-]+[\.]?)*[a-zA-Z0-9]$` // https://tools.ietf.org/html/rfc952
// hostnameRegexStringRFC1123 = `^([a-zA-Z0-9]{1}[a-zA-Z0-9_-]{0,62}){1}(\.[a-zA-Z0-9_]{1}[a-zA-Z0-9_-]{0,62})*?$` // accepts hostname starting with a digit https://tools.ietf.org/html/rfc1123
// fqdnRegexStringRFC1123 = `^([a-zA-Z0-9]{1}[a-zA-Z0-9_-]{0,62})(\.[a-zA-Z0-9_]{1}[a-zA-Z0-9_-]{0,62})*?(\.[a-zA-Z]{1}[a-zA-Z0-9]{0,62})\.?$` // same as hostnameRegexStringRFC1123 but must contain a non numerical TLD (possibly ending with '.')
// btcAddressRegex = `^[13][a-km-zA-HJ-NP-Z1-9]{25,34}$` // bitcoin address
// btcAddressUpperRegexStringBech32 = `^BC1[02-9AC-HJ-NP-Z]{7,76}$` // bitcoin bech32 address https://en.bitcoin.it/wiki/Bech32
// btcAddressLowerRegexStringBech32 = `^bc1[02-9ac-hj-np-z]{7,76}$` // bitcoin bech32 address https://en.bitcoin.it/wiki/Bech32
// ethAddressRegex = `^0x[0-9a-fA-F]{40}$`
// ethAddressUpperRegex = `^0x[0-9A-F]{40}$`
// ethAddressLowerRegex = `^0x[0-9a-f]{40}$`
// uRLEncodedRegex = `(%[A-Fa-f0-9]{2})`
// hTMLEncodedRegex = `&#[x]?([0-9a-fA-F]{2})|(>)|(<)|(")|(&)+[;]?`
// hTMLRegex = `<[/]?([a-zA-Z]+).*?>`
// splitParamsRegex = `'[^']*'|\S+`
)
type ExtString struct {
}
// 向前兼容
func Email() StringSpec {
return ExtString{}.Email()
}
func (ExtString) Email() StringSpec {
return StringSpec{
Pattern: []string{emailRegex},
}
}
func (ExtString) ChinaMobile() StringSpec {
return StringSpec{
MinRuneLen: 11,
MaxRuneLen: 11,
}
}
func (ExtString) UUID() StringSpec {
return StringSpec{
Pattern: []string{uUIDRegex},
}
}
func (ExtString) Base64() StringSpec {
return StringSpec{
Pattern: []string{base64Regex},
}
}
func (ExtString) Base64URL() StringSpec {
return StringSpec{
Pattern: []string{base64URLRegex},
}
}
func (ExtString) DataURI() StringSpec {
return StringSpec{
Pattern: []string{dataURIRegex},
}
}
func (ExtString) Latitude() StringSpec {
return StringSpec{
Pattern: []string{latitudeRegex},
}
}
func (ExtString) Longitude() StringSpec {
return StringSpec{
Pattern: []string{longitudeRegex},
}
}
func (ExtString) Hex() StringSpec {
return StringSpec{
Pattern: []string{hexRegexp},
}
}
func (ExtString) HexColor() StringSpec {
return StringSpec{
Pattern: []string{hexcolorRegex},
}
}
func (ExtString) RGB() StringSpec {
return StringSpec{
Pattern: []string{rgbRegex},
}
}
func (ExtString) RGBA() StringSpec {
return StringSpec{
Pattern: []string{rgbaRegex},
}
}
func (ExtString) HSL() StringSpec {
return StringSpec{
Pattern: []string{hslRegex},
}
}
func (ExtString) HSLA() StringSpec {
return StringSpec{
Pattern: []string{hslaRegex},
}
}
func (ExtString) ASCII() StringSpec {
return StringSpec{
Pattern: []string{aSCIIRegex},
}
}
func (ExtString) PrintableASCII() StringSpec {
return StringSpec{
Pattern: []string{printableASCIIRegex},
}
}