/
Verify.go
63 lines (54 loc) · 1.22 KB
/
Verify.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
package models
import (
"regexp"
"unicode"
)
var (
usernameMatcher *regexp.Regexp
emailMatcher *regexp.Regexp
nameMatcher *regexp.Regexp
collegeMatcher *regexp.Regexp
)
func init() {
usernameMatcher = regexp.MustCompile("^[\\w\\d_\\.]*$")
emailMatcher = regexp.MustCompile("^[\\w\\d_\\.]{2,}\\@[\\w\\d]*\\.[\\w]{2,4}(\\.[\\w]{2,4})?$")
nameMatcher = regexp.MustCompile("^([\\w]{1,}\\s?){1,}$")
collegeMatcher = regexp.MustCompile("^([\\w-]{1,}\\s?){1,}$")
}
func CheckUserName(username string) bool {
if len(username) < 6 {
return false
}
return usernameMatcher.Match([]byte(username))
}
func CheckEmail(email string) bool {
return emailMatcher.Match([]byte(email))
}
func CheckPassword(password string) bool {
if len(password) < 8 {
return false
}
return matchPassword(password)
}
func CheckName(name string) bool {
return nameMatcher.Match([]byte(name))
}
func CheckCollege(college string) bool {
return collegeMatcher.Match([]byte(college))
}
func matchPassword(password string) bool {
var (
letter bool
number bool
)
for _, r := range password {
if unicode.IsLetter(r) {
letter = true
} else if unicode.IsNumber(r) {
number = true
} else {
return false
}
}
return letter && number
}