From aa7d52568b1bcaefa32b773d68101213364ed79e Mon Sep 17 00:00:00 2001 From: zhaoying Date: Tue, 3 Mar 2026 10:24:21 +0800 Subject: [PATCH] fix(web): change string regExp --- web/src/i18n/en.ts | 2 +- web/src/i18n/zh.ts | 2 +- web/src/utils/validator.ts | 5 ++--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/web/src/i18n/en.ts b/web/src/i18n/en.ts index c5c81f13..94dd67cc 100644 --- a/web/src/i18n/en.ts +++ b/web/src/i18n/en.ts @@ -455,6 +455,7 @@ export const en = { recommend: 'Recommend', logoTip: `Supported image formats: JPG, PNG \n Suggested size: square ratio \n Maximum size: ≤ 2MB`, imageSquareRequired: 'Please upload a square image', + nameInvalid: 'Name cannot start or end with a space', }, model: { searchPlaceholder: 'search model…', @@ -545,7 +546,6 @@ export const en = { xinference: "Xinference", gpustack: "Gpustack", bedrock: "Bedrock", - nameInvalid: 'Model name can only contain letters, numbers, underscores and spaces, cannot be empty or pure whitespace', }, modelNew: { group: 'Model Group', diff --git a/web/src/i18n/zh.ts b/web/src/i18n/zh.ts index f63e5981..49632789 100644 --- a/web/src/i18n/zh.ts +++ b/web/src/i18n/zh.ts @@ -1031,6 +1031,7 @@ export const zh = { recommend: '推荐', logoTip: `支持图片格式(JPG、PNG)\n 尺寸:正方形比例 \n 文件大小限制:≤ 2MB`, imageSquareRequired: '请上传正方形比例图片', + nameInvalid: '不能是空格开头或结尾', }, model: { searchPlaceholder: '搜索模型…', @@ -1179,7 +1180,6 @@ export const zh = { xinference: "Xinference", gpustack: "Gpustack", bedrock: "Bedrock", - nameInvalid: '模型名称只能包含字母、数字、下划线和空格, 不能为空或纯空格', }, timezones: { 'Asia/Shanghai': '中国标准时间 (UTC+8)', diff --git a/web/src/utils/validator.ts b/web/src/utils/validator.ts index c55c52ca..650266ab 100644 --- a/web/src/utils/validator.ts +++ b/web/src/utils/validator.ts @@ -45,6 +45,5 @@ export const validateSquareImage = (errorMessage: string = 'Image must be square }; }; -// - Cannot be empty or pure whitespace -// - Cannot start with a space -export const stringRegExp = /^[a-zA-Z0-9\u4e00-\u9fa5][a-zA-Z0-9\u4e00-\u9fa5\s]*$/ \ No newline at end of file +// - Cannot start or end with a space +export const stringRegExp = /^(?!\s).*(?