mirror of
https://gitee.com/johng/gf
synced 2026-06-06 16:21:40 +08:00
Merge pull request #1027 from arieslee/gvalid-phone-loose
Add 172-segment verification rules, add loose mobile number verificat…
This commit is contained in:
@ -58,6 +58,7 @@ var (
|
||||
"date-format": {},
|
||||
"email": {},
|
||||
"phone": {},
|
||||
"phone-loose": {},
|
||||
"telephone": {},
|
||||
"passport": {},
|
||||
"password": {},
|
||||
@ -356,6 +357,7 @@ func doCheckBuildInRules(
|
||||
// 1. China Mobile:
|
||||
// 134, 135, 136, 137, 138, 139, 150, 151, 152, 157, 158, 159, 182, 183, 184, 187, 188,
|
||||
// 178(4G), 147(Net);
|
||||
// 172
|
||||
//
|
||||
// 2. China Unicom:
|
||||
// 130, 131, 132, 155, 156, 185, 186 ,176(4G), 145(Net), 175
|
||||
@ -372,7 +374,12 @@ func doCheckBuildInRules(
|
||||
// 6. 2018:
|
||||
// 16x, 19x
|
||||
case "phone":
|
||||
match = gregex.IsMatchString(`^13[\d]{9}$|^14[5,7]{1}\d{8}$|^15[^4]{1}\d{8}$|^16[\d]{9}$|^17[0,3,5,6,7,8]{1}\d{8}$|^18[\d]{9}$|^19[\d]{9}$`, valueStr)
|
||||
match = gregex.IsMatchString(`^13[\d]{9}$|^14[5,7]{1}\d{8}$|^15[^4]{1}\d{8}$|^16[\d]{9}$|^17[0,2,3,5,6,7,8]{1}\d{8}$|^18[\d]{9}$|^19[\d]{9}$`, valueStr)
|
||||
// Loose mobile phone number verification(宽松的手机号验证)
|
||||
// As long as the 11 digit numbers beginning with
|
||||
// 13, 14, 15, 16, 17, 18, 19 can pass the verification (只要满足 13、14、15、16、17、18、19开头的11位数字都可以通过验证)
|
||||
case "phone-loose":
|
||||
match = gregex.IsMatchString(`^1(3|4|5|6|7|8|9)\d{9}$`, valueStr)
|
||||
|
||||
// Telephone number:
|
||||
// "XXXX-XXXXXXX"
|
||||
|
||||
@ -237,6 +237,22 @@ func Test_Phone(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func Test_PhoneLoose(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
err1 := gvalid.Check("13333333333", "phone-loose", nil)
|
||||
err2 := gvalid.Check("15555555555", "phone-loose", nil)
|
||||
err3 := gvalid.Check("16666666666", "phone-loose", nil)
|
||||
err4 := gvalid.Check("23333333333", "phone-loose", nil)
|
||||
err5 := gvalid.Check("1333333333", "phone-loose", nil)
|
||||
err6 := gvalid.Check("10333333333", "phone-loose", nil)
|
||||
t.Assert(err1, nil)
|
||||
t.Assert(err2, nil)
|
||||
t.Assert(err3, nil)
|
||||
t.AssertNE(err4, nil)
|
||||
t.AssertNE(err5, nil)
|
||||
t.AssertNE(err6, nil)
|
||||
})
|
||||
}
|
||||
func Test_Telephone(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
rule := "telephone"
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
"gf.gvalid.rule.date-format" = ":attribute 日期格式不满足:format"
|
||||
"gf.gvalid.rule.email" = ":attribute 邮箱地址格式不正确"
|
||||
"gf.gvalid.rule.phone" = ":attribute 手机号码格式不正确"
|
||||
"gf.gvalid.rule.phone-loose" = ":attribute 手机号码格式不正确"
|
||||
"gf.gvalid.rule.telephone" = ":attribute 电话号码格式不正确"
|
||||
"gf.gvalid.rule.passport" = ":attribute 账号格式不合法,必需以字母开头,只能包含字母、数字和下划线,长度在6~18之间"
|
||||
"gf.gvalid.rule.password" = ":attribute 密码格式不合法,密码格式为任意6-18位的可见字符"
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
"gf.gvalid.rule.date-format" = "The :attribute value does not match the format :format"
|
||||
"gf.gvalid.rule.email" = "The :attribute value must be a valid email address"
|
||||
"gf.gvalid.rule.phone" = "The :attribute value must be a valid phone number"
|
||||
"gf.gvalid.rule.phone-loose" = "The :attribute value must be a valid phone number"
|
||||
"gf.gvalid.rule.telephone" = "The :attribute value must be a valid telephone number"
|
||||
"gf.gvalid.rule.passport" = "The :attribute value is not a valid passport format"
|
||||
"gf.gvalid.rule.password" = "The :attribute value is not a valid passport format"
|
||||
|
||||
Reference in New Issue
Block a user