瀏覽代碼

add regex

huai-sian 2 年之前
父節點
當前提交
c248456abb
共有 2 個文件被更改,包括 18 次插入8 次删除
  1. 10 4
      html/login.js
  2. 8 4
      html/register.js

+ 10 - 4
html/login.js

@@ -37,6 +37,7 @@ function login(){
     var url = "https://www.choozmo.com:8887/login";
     var username = $('#username').val();
     var password = $('#password').val();
+    var regex = new RegExp("^[a-zA-Z0-9 ]+$");
 
     if (username == '' || password == '') {
         let title = "登入失敗";
@@ -57,10 +58,9 @@ function login(){
         return;
     }
 
-    if (/.*[\u4e00-\u9fa5]+.*$/.test(username)) {
+    if (!regex.test(username)) {
         let title = "字元有誤";
         let text = "名稱僅得包含英文及數字";
-
         if (lang == 'en') { 
             title = "Invalid username!";
             text = "Please enter valid username";
@@ -90,7 +90,7 @@ function login(){
         "lockScroll": false,
         "overlayZIndex": 10,
         "spinnerZIndex": 11
-      });
+    });
     
     var data = "grant_type=&username=" + username + "&password="+password+"&scope=&client_id=&client_secret=";
     const headers = {
@@ -124,7 +124,7 @@ function login(){
             btnLoginPage.style.display = 'none';
         } else if (res.data.access_token!=null && res.data.veri != 'ok') {
             var title = "請前往信箱完成驗證";
-
+            JsLoadingOverlay.hide();
             if (lang == 'en') { // 英文版訊息
                 title = "Please check your email box to get validated!"
             }
@@ -147,6 +147,9 @@ function login(){
                 text: responseOBJ.detail,
                 confirmButtonColor: '#3085d6',
             });
+            window.setTimeout(() => {
+                location.reload();
+            }, 4000)
         }
         
     }).catch(err => {
@@ -161,6 +164,9 @@ function login(){
             icon: 'error',
             confirmButtonColor: '#3085d6',
         });
+        window.setTimeout(() => {
+            location.reload();
+        }, 4000)
     })
 }
 /*     var xhr = new XMLHttpRequest();

+ 8 - 4
html/register.js

@@ -82,7 +82,8 @@ function validateConfirmPsd(psd1, psd2) {
 
 function validateConfirmName() {
     let username = $('#register [name = "username"]').val();
-    if(!/.*[\u4e00-\u9fa5]+.*$/.test(username)) {
+    var regex = new RegExp("^[a-zA-Z0-9 ]+$");
+    if(regex.test(username)) {
         $('#register [name = "username"]').removeClass('error');
         $('.error-text').remove();
         return true;
@@ -100,9 +101,9 @@ function register() {
     let email = $('#register [name = "email"]').val();
     let password = $('#register [name = "password"]').val();
     let confirm_psd = $('#register #confirm_password').val();
-
+    var regex = new RegExp("^[a-zA-Z0-9 ]+$");
     // 註冊資料檢查
-    if (username == '' || password == '') {
+    if (userName == '' || password == '') {
         let title = "註冊失敗";
         let text = "請先輸入您的帳號/密碼";
 
@@ -121,7 +122,7 @@ function register() {
         return;
     }
 
-    if (/.*[\u4e00-\u9fa5]+.*$/.test(username)) {
+    if (!regex.test(userName)) {
         let title = "字元有誤";
         let text = "名稱僅得包含英文及數字";
 
@@ -197,6 +198,9 @@ function register() {
                 icon: 'error',
                 confirmButtonColor: '#3085d6',
             });
+            window.setTimeout(() => {
+                location.reload();
+            }, 4000);
         })
     }
 }