1
0
mirror of https://github.com/astaxie/beego.git synced 2025-06-11 07:10:39 +00:00

Move many PR's change here since the original authors are responseless

This commit is contained in:
Ming Deng
2020-06-23 21:18:58 +08:00
parent 96658121dc
commit 3ce68d6a30
5 changed files with 73 additions and 43 deletions

View File

@ -253,44 +253,68 @@ func TestBase64(t *testing.T) {
func TestMobile(t *testing.T) {
valid := Validation{}
if valid.Mobile("19800008888", "mobile").Ok {
t.Error("\"19800008888\" is a valid mobile phone number should be false")
validMobiles := []string{
"19800008888",
"18800008888",
"18000008888",
"8618300008888",
"+8614700008888",
"17300008888",
"+8617100008888",
"8617500008888",
"8617400008888",
"16200008888",
"16500008888",
"16600008888",
"16700008888",
"13300008888",
"14900008888",
"15300008888",
"17300008888",
"17700008888",
"18000008888",
"18900008888",
"19100008888",
"19900008888",
"19300008888",
"13000008888",
"13100008888",
"13200008888",
"14500008888",
"15500008888",
"15600008888",
"16600008888",
"17100008888",
"17500008888",
"17600008888",
"18500008888",
"18600008888",
"13400008888",
"13500008888",
"13600008888",
"13700008888",
"13800008888",
"13900008888",
"14700008888",
"15000008888",
"15100008888",
"15200008888",
"15800008888",
"15900008888",
"17200008888",
"17800008888",
"18200008888",
"18300008888",
"18400008888",
"18700008888",
"18800008888",
"19800008888",
}
if !valid.Mobile("18800008888", "mobile").Ok {
t.Error("\"18800008888\" is a valid mobile phone number should be true")
}
if !valid.Mobile("18000008888", "mobile").Ok {
t.Error("\"18000008888\" is a valid mobile phone number should be true")
}
if !valid.Mobile("8618300008888", "mobile").Ok {
t.Error("\"8618300008888\" is a valid mobile phone number should be true")
}
if !valid.Mobile("+8614700008888", "mobile").Ok {
t.Error("\"+8614700008888\" is a valid mobile phone number should be true")
}
if !valid.Mobile("17300008888", "mobile").Ok {
t.Error("\"17300008888\" is a valid mobile phone number should be true")
}
if !valid.Mobile("+8617100008888", "mobile").Ok {
t.Error("\"+8617100008888\" is a valid mobile phone number should be true")
}
if !valid.Mobile("8617500008888", "mobile").Ok {
t.Error("\"8617500008888\" is a valid mobile phone number should be true")
}
if valid.Mobile("8617400008888", "mobile").Ok {
t.Error("\"8617400008888\" is a valid mobile phone number should be false")
}
if !valid.Mobile("16200008888", "mobile").Ok {
t.Error("\"16200008888\" is a valid mobile phone number should be true")
}
if !valid.Mobile("16500008888", "mobile").Ok {
t.Error("\"16500008888\" is a valid mobile phone number should be true")
}
if !valid.Mobile("16600008888", "mobile").Ok {
t.Error("\"16600008888\" is a valid mobile phone number should be true")
}
if !valid.Mobile("16700008888", "mobile").Ok {
t.Error("\"16700008888\" is a valid mobile phone number should be true")
for _, m := range validMobiles {
if !valid.Mobile(m, "mobile").Ok {
t.Error(m + " is a valid mobile phone number should be true")
}
}
}

View File

@ -632,7 +632,7 @@ func (b Base64) GetLimitValue() interface{} {
}
// just for chinese mobile phone number
var mobilePattern = regexp.MustCompile(`^((\+86)|(86))?(1(([35][0-9])|[8][0-9]|[7][01356789]|[4][579]|[6][2567]))\d{8}$`)
var mobilePattern = regexp.MustCompile(`^((\+86)|(86))?1([356789][0-9]|4[579]|6[67]|7[0135678]|9[189])[0-9]{8}$`)
// Mobile check struct
type Mobile struct {