Browse Source

update[litemall-wx]: 手机号支持验证

Junling Bu 7 years ago
parent
commit
17e8a86bc7

+ 18 - 1
litemall-wx/pages/auth/register/register.js

@@ -1,4 +1,6 @@
 var api = require('../../../config/api.js');
 var api = require('../../../config/api.js');
+var check = require('../../../utils/check.js');
+
 var app = getApp();
 var app = getApp();
 Page({
 Page({
   data: {
   data: {
@@ -65,6 +67,15 @@ Page({
       return false;
       return false;
     }
     }
 
 
+    if (!check.isValidPhone(this.data.mobile)) {
+      wx.showModal({
+        title: '错误信息',
+        content: '手机号输入不正确',
+        showCancel: false
+      });
+      return false;
+    }
+    
     wx.request({
     wx.request({
       url: api.AuthRegister,
       url: api.AuthRegister,
       data: {
       data: {
@@ -90,7 +101,13 @@ Page({
               });
               });
             }
             }
           });
           });
-
+        }
+        else{
+          wx.showModal({
+            title: '错误信息',
+            content: res.data.errmsg,
+            showCancel: false
+          });
         }
         }
       }
       }
     });
     });

+ 11 - 0
litemall-wx/pages/auth/reset/reset.js

@@ -1,4 +1,6 @@
 var api = require('../../../config/api.js');
 var api = require('../../../config/api.js');
+var check = require('../../../utils/check.js');
+
 var app = getApp();
 var app = getApp();
 Page({
 Page({
   data: {
   data: {
@@ -46,6 +48,15 @@ Page({
       return false;
       return false;
     }
     }
 
 
+    if (!check.isValidPhone(this.data.mobile)) {
+      wx.showModal({
+        title: '错误信息',
+        content: '手机号输入不正确',
+        showCancel: false
+      });
+      return false;
+    }
+
     if (this.data.password.length < 3) {
     if (this.data.password.length < 3) {
       wx.showModal({
       wx.showModal({
         title: '错误信息',
         title: '错误信息',

+ 12 - 0
litemall-wx/utils/check.js

@@ -0,0 +1,12 @@
+function isValidPhone(str) {
+  var myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
+  if (!myreg.test(str)) {
+    return false;
+  } else {
+    return true;
+  }
+}  
+
+module.exports = {
+  isValidPhone
+}