-
Notifications
You must be signed in to change notification settings - Fork 8
/
str_length.go
47 lines (42 loc) · 1.16 KB
/
str_length.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
package filter
import "unicode/utf8"
// MinLength 最小长度
func (self *Str) MinLength(min int, customError ...string) StrType {
if self.err != nil || self.currentValue == "" {
return self
}
if len(self.currentValue) < min {
self.err = wrapError(self.name, "", customError...)
}
return self
}
// MinUTF8Length UTF8编码最小长度
func (self *Str) MinUTF8Length(min int, customError ...string) StrType {
if self.err != nil || self.currentValue == "" {
return self
}
if utf8.RuneCountInString(self.currentValue) < min {
self.err = wrapError(self.name, "", customError...)
}
return self
}
// MaxLength 最大长度
func (self *Str) MaxLength(max int, customError ...string) StrType {
if self.err != nil || self.currentValue == "" {
return self
}
if len(self.currentValue) > max {
self.err = wrapError(self.name, "", customError...)
}
return self
}
// MaxUTF8Length UTF8编码最大长度
func (self *Str) MaxUTF8Length(max int, customError ...string) StrType {
if self.err != nil || self.currentValue == "" {
return self
}
if utf8.RuneCountInString(self.currentValue) > max {
self.err = wrapError(self.name, "", customError...)
}
return self
}