-
Notifications
You must be signed in to change notification settings - Fork 0
/
string.go
79 lines (59 loc) · 1.25 KB
/
string.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
package util
import (
"regexp"
"strconv"
"strings"
"time"
)
var validEmail = regexp.MustCompile(`^.+@.*\..*$`)
var validMobile = regexp.MustCompile(`^1\d{10}$`)
var nonDigitals = regexp.MustCompile(`^\D*$`)
func IsEmail(s string) bool {
return validEmail.MatchString(s)
}
func IsMobile( s string) bool {
return validMobile.MatchString(s)
}
// 去掉非数字字符后,再转换成字符串
func ForceToInt64( s string) int64 {
result := nonDigitals.ReplaceAll([]byte(s), []byte(""))
if result == nil || len(result) == 0 {
return 0
}
s2 := string(result)
value, _ := strconv.ParseInt(s2, 10, 0)
return value
}
func ParseScreen(screen string ) (long int, short int) {
parts := strings.Split(screen, "x")
if len(parts) == 2 {
var err error
long, err = strconv.Atoi(parts[0])
if err == nil {
short , err = strconv.Atoi(parts[1])
if err == nil {
if short > long {
tmp := long
long = short
short = tmp
}
}
}
}
return long, short
}
func IsEmpty(s string) bool {
s = strings.TrimSpace(s)
return s == ""
}
func IsNotEmpty(s string) bool {
s = strings.TrimSpace(s)
return s != ""
}
func IsDate(s string) bool {
s = strings.TrimSpace(s)
_, err := time.Parse("2006-1-2", s)
return err == nil
}
func A() {
}