Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

fix: update admin name validation

Luffy18aef3aaad52
diff --git a/i18n/en_US.yaml b/i18n/en_US.yaml
index 03de7411..db5052a3 100644
--- a/i18n/en_US.yaml
+++ b/i18n/en_US.yaml
@@ -1699,7 +1699,7 @@ ui:
admin_name:
label: Name
msg: Name cannot be empty.
- character: 'Must use the character set "a-z", "0-9", " - . _"'
+ character: 'Must use the character set "a-z", "A-Z", "0-9", " - . _"'
msg_max_length: Name must be at maximum 30 characters in length.
admin_password:
label: Password
diff --git a/i18n/zh_CN.yaml b/i18n/zh_CN.yaml
index e16c0699..73c5c9a0 100644
--- a/i18n/zh_CN.yaml
+++ b/i18n/zh_CN.yaml
@@ -1662,7 +1662,7 @@ ui:
admin_name:
label: 名字
msg: 名字不能为空。
- character: '只能由 "a-z", "0-9", " - . _" 组成'
+ character: '只能由 "a-z"、"A-Z"、"0-9"、" - . _" 组成'
msg_max_length: 名字长度不能超过 30 个字符。
admin_password:
label: 密码
diff --git a/ui/src/pages/Install/components/FourthStep/index.tsx b/ui/src/pages/Install/components/FourthStep/index.tsx
index 2c059851..6b37041c 100644
--- a/ui/src/pages/Install/components/FourthStep/index.tsx
+++ b/ui/src/pages/Install/components/FourthStep/index.tsx
@@ -45,6 +45,7 @@ const Index: FC<Props> = ({ visible, data, changeCallback, nextCallback }) => {
password,
email,
} = data;
+ const nameRegex = /^[\w.-\s]{2,30}$/;
if (!site_name.value) {
bol = false;
@@ -115,19 +116,19 @@ const Index: FC<Props> = ({ visible, data, changeCallback, nextCallback }) => {
isInvalid: true,
errorMsg: t('admin_name.msg'),
};
- } else if (/[^a-z0-9\-._]/.test(name.value)) {
+ } else if (name.value.length < 2 || name.value.length > 30) {
bol = false;
data.name = {
value: name.value,
isInvalid: true,
- errorMsg: t('admin_name.character'),
+ errorMsg: t('admin_name.msg_max_length'),
};
- } else if (data.name.value.length > 30) {
+ } else if (!nameRegex.test(name.value)) {
bol = false;
data.name = {
- value: data.name.value,
+ value: name.value,
isInvalid: true,
- errorMsg: t('admin_name.msg_max_length'),
+ errorMsg: t('admin_name.character'),
};
}