Browse Source

Order action, check mobile phone and email

Vova Tkach 5 years ago
parent
commit
b41292b8ae
2 changed files with 8 additions and 2 deletions
  1. 3 2
      modules/module_shop_order.go
  2. 5 0
      utils/utils.go

+ 3 - 2
modules/module_shop_order.go

@@ -5,6 +5,7 @@ import (
 
 	"golang-fave/engine/basket"
 	"golang-fave/engine/wrapper"
+	"golang-fave/utils"
 )
 
 func (this *Modules) RegisterAction_ShopOrder() *Action {
@@ -51,13 +52,13 @@ func (this *Modules) RegisterAction_ShopOrder() *Action {
 			}
 		}
 		if (*wrap.Config).Shop.Orders.RequiredFields.MobilePhone != 0 {
-			if strings.TrimSpace(pf_client_phone) == "" {
+			if strings.TrimSpace(pf_client_phone) == "" || !utils.IsValidMobile(pf_client_phone) {
 				wrap.Write(`{"error": true, "field": "client_phone", "variable": "ShopOrderEmptyMobilePhone"}`)
 				return
 			}
 		}
 		if (*wrap.Config).Shop.Orders.RequiredFields.EmailAddress != 0 {
-			if strings.TrimSpace(pf_client_email) == "" {
+			if strings.TrimSpace(pf_client_email) == "" || !utils.IsValidEmail(pf_client_email) {
 				wrap.Write(`{"error": true, "field": "client_email", "variable": "ShopOrderEmptyEmailAddress"}`)
 				return
 			}

+ 5 - 0
utils/utils.go

@@ -60,6 +60,11 @@ func IsFloat(str string) bool {
 	return false
 }
 
+func IsValidMobile(str string) bool {
+	regexpeChars := regexp.MustCompile(`^\+([1-9]{1})([0-9]{1})([0-9]{3})([0-9]{7})$`)
+	return regexpeChars.MatchString(str)
+}
+
 func IsValidEmail(email string) bool {
 	regexpe := regexp.MustCompile(`^[a-z0-9._%+\-]+@[a-z0-9.\-]+\.[a-z]{2,4}$`)
 	return regexpe.MatchString(email)