浏览代码

no message

xingzai 3 年之前
父节点
当前提交
be2e72fd7d
共有 3 个文件被更改,包括 17 次插入2 次删除
  1. 8 0
      controllers/user.go
  2. 6 0
      utils/common.go
  3. 3 2
      utils/constants.go

+ 8 - 0
controllers/user.go

@@ -1099,6 +1099,14 @@ func (this *UserController) AddOutboundMobile() {
 		br.ErrMsg = "参数解析失败,Err:" + err.Error()
 		return
 	}
+	if !utils.ValidateFixedTelephoneFormatat(req.OutboundMobile) && !utils.ValidateMobileFormatat(req.OutboundMobile) {
+		br.Msg = "号码格式有误,请重新填写!"
+		return
+	}
+	if req.OutboundMobile == "" {
+		br.Msg = "请填写区号!"
+		return
+	}
 	item := new(models.OutboundMobileItem)
 	item.OutboundMobile = req.OutboundMobile
 	item.OutboundCountryCode = req.OutboundCountryCode

+ 6 - 0
utils/common.go

@@ -215,6 +215,12 @@ func ValidateMobileFormatat(mobileNum string) bool {
 	return reg.MatchString(mobileNum)
 }
 
+//验证是否是固定电话
+func ValidateFixedTelephoneFormatat(mobileNum string) bool {
+	reg := regexp.MustCompile(RegularFixedTelephone)
+	return reg.MatchString(mobileNum)
+}
+
 //判断文件是否存在
 func FileIsExist(filePath string) bool {
 	_, err := os.Stat(filePath)

+ 3 - 2
utils/constants.go

@@ -26,8 +26,9 @@ const (
 
 //手机号,电子邮箱正则
 const (
-	RegularMobile = "^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(18[0-9])|(17[0-9])|(16[0-9])|(19[0-9]))\\d{8}$" //手机号码
-	RegularEmail  = `\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*`                                             //匹配电子邮箱
+	RegularMobile         = "^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(18[0-9])|(17[0-9])|(16[0-9])|(19[0-9]))\\d{8}$" //手机号码
+	RegularFixedTelephone = "^(\\(\\d{3,4}\\)|\\d{3,4}-|\\s)?\\d{7,14}$"                                              //手机号码
+	RegularEmail          = `\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*`                                             //匹配电子邮箱
 )
 
 //聚合短信