diff --git a/frontend/src/lang/en.js b/frontend/src/lang/en.js index ded6766bf5..22a06e33ad 100644 --- a/frontend/src/lang/en.js +++ b/frontend/src/lang/en.js @@ -651,6 +651,7 @@ export default { input_password: 'Please input a password', input_phone: 'Please enter the phone number', input_roles: 'Please select role', + user_name_pattern_error: 'IDs can only contain alphanumeric underscores and - and start with a letter!', special_characters_are_not_supported: 'Special characters are not supported', mobile_number_format_is_incorrect: 'Incorrect format of mobile phone number', email_format_is_incorrect: 'The mailbox format is incorrect', diff --git a/frontend/src/lang/tw.js b/frontend/src/lang/tw.js index f5c2cfac92..736c8ca685 100644 --- a/frontend/src/lang/tw.js +++ b/frontend/src/lang/tw.js @@ -652,6 +652,7 @@ export default { input_roles: '請選擇角色', select_users: '請選擇用戶', select_gender: '請選擇性別', + user_name_pattern_error: 'ID只能包含字母数字下划线以及-并以字母开头!', special_characters_are_not_supported: '不支持特殊字符', mobile_number_format_is_incorrect: '手機號碼格式不正確', email_format_is_incorrect: '郵箱格式不正確', diff --git a/frontend/src/lang/zh.js b/frontend/src/lang/zh.js index 3e9f6fa760..a151018127 100644 --- a/frontend/src/lang/zh.js +++ b/frontend/src/lang/zh.js @@ -651,6 +651,7 @@ export default { input_roles: '请选择角色', select_users: '请选择用户', select_gender: '请选择性别', + user_name_pattern_error: 'ID只能包含字母数字下划线以及-并以字母开头!', special_characters_are_not_supported: '不支持特殊字符', mobile_number_format_is_incorrect: '手机号码格式不正确', email_format_is_incorrect: '邮箱格式不正确', diff --git a/frontend/src/views/system/user/UserEditer.vue b/frontend/src/views/system/user/UserEditer.vue index 0e35c704c1..4e7fe43bf9 100644 --- a/frontend/src/views/system/user/UserEditer.vue +++ b/frontend/src/views/system/user/UserEditer.vue @@ -264,7 +264,7 @@ export default { }, { required: true, - pattern: '^[^\u4e00-\u9fa5]+$', + pattern: '^[a-zA-Z][a-zA-Z0-9_-]*$', message: this.$t('user.special_characters_are_not_supported'), trigger: 'blur' } @@ -281,11 +281,8 @@ export default { message: this.$t('commons.input_limit', [2, 50]), trigger: 'blur' }, - { - required: true, - message: this.$t('user.special_characters_are_not_supported'), - trigger: 'blur' - } + { required: true, validator: this.validateNickname, trigger: 'blur' } + ], phone: [ { @@ -411,6 +408,17 @@ export default { callback() } }, + validateNickname(rule, value, callback) { + const pattern = "[\\u00A0\\s\"`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“'。,、?]" + const regep = new RegExp(pattern) + + if (regep.test(value)) { + const msg = this.$t('user.special_characters_are_not_supported') + callback(new Error(msg)) + } else { + callback() + } + }, create() { this.formType = 'add' this.form = Object.assign({}, JSON.parse(JSON.stringify(this.defaultForm)))