fix:注册界面格式校验修复
This commit is contained in:
@@ -254,9 +254,6 @@ const local: any = {
|
|||||||
birthDate: 'Birth Date',
|
birthDate: 'Birth Date',
|
||||||
birthDatePlaceholder: 'Please select birth date',
|
birthDatePlaceholder: 'Please select birth date',
|
||||||
birthDateRequired: 'Please select birth date',
|
birthDateRequired: 'Please select birth date',
|
||||||
usernameLengthLimit:"Username is too short",
|
|
||||||
usernameExists:"The username is already registered",
|
|
||||||
usernameRequired:"The username cannot be empty",
|
|
||||||
phoneInvalid:"The mobile phone number is incorrect",
|
phoneInvalid:"The mobile phone number is incorrect",
|
||||||
phoneExists:"The mobile phone number has been registered",
|
phoneExists:"The mobile phone number has been registered",
|
||||||
emailInvalid:"The email is incorrect",
|
emailInvalid:"The email is incorrect",
|
||||||
@@ -265,6 +262,12 @@ const local: any = {
|
|||||||
codeRequired:"The code cannot be empty",
|
codeRequired:"The code cannot be empty",
|
||||||
passwordRequired:"The password cannot be empty",
|
passwordRequired:"The password cannot be empty",
|
||||||
passwordLength:"The password is too short",
|
passwordLength:"The password is too short",
|
||||||
|
usernameRequired: 'Please enter username',
|
||||||
|
usernameLengthLimit: 'Username must be 3-20 characters',
|
||||||
|
usernameFormatError: 'Username can only contain letters, numbers and underscore',
|
||||||
|
usernameStartWithLetter: 'Username must start with a letter',
|
||||||
|
usernameExists: 'Username already exists',
|
||||||
|
validationError: 'Validation failed, please try again'
|
||||||
},
|
},
|
||||||
resetPwd: {
|
resetPwd: {
|
||||||
title: 'Reset Password'
|
title: 'Reset Password'
|
||||||
|
|||||||
@@ -254,9 +254,6 @@ const local:any = {
|
|||||||
birthDate: '出生日期',
|
birthDate: '出生日期',
|
||||||
birthDatePlaceholder: '请选择出生日期',
|
birthDatePlaceholder: '请选择出生日期',
|
||||||
birthDateRequired: '请选择出生日期',
|
birthDateRequired: '请选择出生日期',
|
||||||
usernameLengthLimit:"用户名太短",
|
|
||||||
usernameExists:"用户名已经注册",
|
|
||||||
usernameRequired:"用户名不能为空",
|
|
||||||
phoneInvalid:"手机号格式不正确",
|
phoneInvalid:"手机号格式不正确",
|
||||||
phoneExists:"手机号已经注册",
|
phoneExists:"手机号已经注册",
|
||||||
emailInvalid:"邮箱格式不正确",
|
emailInvalid:"邮箱格式不正确",
|
||||||
@@ -265,6 +262,12 @@ const local:any = {
|
|||||||
codeRequired:"验证码不能为空",
|
codeRequired:"验证码不能为空",
|
||||||
passwordRequired:"密码不能为空",
|
passwordRequired:"密码不能为空",
|
||||||
passwordLength:"密码太短",
|
passwordLength:"密码太短",
|
||||||
|
usernameRequired: '请输入用户名',
|
||||||
|
usernameLengthLimit: '用户名长度必须在3-20个字符之间',
|
||||||
|
usernameFormatError: '用户名只能包含字母、数字和下划线',
|
||||||
|
usernameStartWithLetter: '用户名必须以字母开头',
|
||||||
|
usernameExists: '该用户名已被使用',
|
||||||
|
validationError: '验证失败,请重试'
|
||||||
},
|
},
|
||||||
resetPwd: {
|
resetPwd: {
|
||||||
title: '重置密码'
|
title: '重置密码'
|
||||||
|
|||||||
@@ -71,15 +71,38 @@ const securityModel = reactive<SecurityFormModel>({
|
|||||||
// 第一步表单验证规则
|
// 第一步表单验证规则
|
||||||
const basicRules = computed<Record<string, Rule | Rule[]>>(() => {
|
const basicRules = computed<Record<string, Rule | Rule[]>>(() => {
|
||||||
const validateUsername = async (_rule: Rule, value: string) => {
|
const validateUsername = async (_rule: Rule, value: string) => {
|
||||||
if (value && (value.length < 4 || value.length > 20)) {
|
// 空值检查
|
||||||
|
if (!value) {
|
||||||
|
return Promise.reject(t('page.login.register.usernameRequired'));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 长度检查 (3-20字符)
|
||||||
|
if (value.length < 3 || value.length > 20) {
|
||||||
return Promise.reject(t('page.login.register.usernameLengthLimit'));
|
return Promise.reject(t('page.login.register.usernameLengthLimit'));
|
||||||
}
|
}
|
||||||
if (value) {
|
|
||||||
|
// 格式检查 (只允许字母、数字、下划线)
|
||||||
|
const usernamePattern = /^[a-zA-Z0-9_]+$/;
|
||||||
|
if (!usernamePattern.test(value)) {
|
||||||
|
return Promise.reject(t('page.login.register.usernameFormatError'));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 首字符必须是字母
|
||||||
|
if (!/^[a-zA-Z]/.test(value)) {
|
||||||
|
return Promise.reject(t('page.login.register.usernameStartWithLetter'));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 重复性检查
|
||||||
|
try {
|
||||||
const { exists } = await authStore.checkUserRepeat({ username: value, authType: 'u' });
|
const { exists } = await authStore.checkUserRepeat({ username: value, authType: 'u' });
|
||||||
if (exists) {
|
if (exists) {
|
||||||
return Promise.reject(t('page.login.register.usernameExists'));
|
return Promise.reject(t('page.login.register.usernameExists'));
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Username validation error:', error);
|
||||||
|
return Promise.reject(t('page.login.register.validationError'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user