Ver código fonte

refactor: 允许用户name使用中文

fanyanpeng 2 anos atrás
pai
commit
25d2db7836
1 arquivos alterados com 2 adições e 2 exclusões
  1. 2 2
      server/controller/user.js

+ 2 - 2
server/controller/user.js

@@ -160,7 +160,7 @@ class UserController {
   // 验证注册数据是否合法
   static validateRegistrationData(name, password, phone, email) {
     const emailRegex  = /^[a-zA-Z0-9_-]+@([a-zA-Z0-9]+\.)+(com|cn|net|org)$/;
-    const nameRegex  = /^\w+$/; //由字母、数字、下划线组成且不包含其他字符的字符串
+    const nameRegex  = /^[\u4e00-\u9fa5a-zA-Z0-9_]+$/; //由中文、字母、数字、下划线组成且不包含其他字符的字符串
 
     if (!emailRegex.test(email)) {
       throw new Error('邮箱格式有误');
@@ -179,7 +179,7 @@ class UserController {
     }
 
     if (!nameRegex.test(name)) {
-      throw new Error('用户名只能包含字母、数字和下划线');
+      throw new Error('用户名只能包含中文、字母、数字和下划线');
     }
 
   }