/
verify.go
55 lines (46 loc) · 1.84 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
package util
import (
"regexp"
)
//email verify
func VerifyEmailFormat(email string) bool {
// if email == "" {
// return false
// }
//pattern := `\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*` //匹配电子邮箱
pattern := `^[0-9a-z][_.0-9a-z-]{0,31}@([0-9a-z][0-9a-z-]{0,30}[0-9a-z]\.){1,4}[a-z]{2,4}$`
reg := regexp.MustCompile(pattern)
return reg.MatchString(email)
}
//mobile verify
func VerifyMobileFormat(mobileNum string) bool {
// if mobileNum == "" {
// return false
// }
regular := "^((13[0-9])|(14[5,7])|(15[0-3,5-9])|(17[0,3,5-8])|(18[0-9])|166|198|199|(147))\\d{8}$"
reg := regexp.MustCompile(regular)
return reg.MatchString(mobileNum)
}
//username verify
func VerifyNameFormat(name string) bool {
// if name == "" {
// return false
// }
regular := "/^[a-z0-9_-]{3,16}$/"
reg := regexp.MustCompile(regular)
return reg.MatchString(name)
}
// 用户名: /^[a-z0-9_-]{3,16}$/
// 密码: /^[a-z0-9_-]{6,18}$/
// 十六进制值: /^#?([a-f0-9]{6}|[a-f0-9]{3})$/
// 电子邮箱 : /^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/
// /^[a-z\d]+(\.[a-z\d]+)*@([\da-z](-[\da-z])?)+(\.{1,2}[a-z]+)+$/
// URL: /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/
// IP 地址: /((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)/
// /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/
// HTML 标签: /^<([a-z]+)([^<]+)*(?:>(.*)<\/\1>|\s+\/>)$/
// 删除代码\\注释: (?<!http:|\S)//.*$
// Unicode编码中的汉字范围: /^[\u2E80-\u9FFF]+$/
// ————————————————
// 版权声明:本文为CSDN博主「dingCode」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
// 原文链接:https://blog.csdn.net/daimading/article/details/88390302