限制特殊符号输入

This commit is contained in:
Linzm committed 2025-11-27 10:58:54 +08:00
1 parent 8ae713aef9
commit 1c89f495a7
1 file changed
+6 -7
+6 -7
View File
@@ -952,11 +952,11 @@ const frontTextShow = (event: any, isFront: boolean | null = null) => {
const shapeText = ref('') const shapeText = ref('')
const changeShapeText = (e: any) => { const changeShapeText = (e: any) => {
console.log('changeShapeText', e.target.value) console.log('changeShapeText', e.target.value)
// if (!validateInput(e.target.value)) { if (!validateInput(e.target.value)) {
// showToast('输入的文字不能包含特殊符号!') showToast('输入的文字不能包含特殊符号!')
// shapeText.value = e.target.value.replace(/[^a-zA-Z0-9\u4e00-\u9fa5\s]/g, ''); shapeText.value = e.target.value.replace(/[^a-zA-Z0-9\u4e00-\u9fff\u3040-\u309f\u30a0-\u30ff\uac00-\ud7a3\u00c0-\u017f\s~!@#¥%……&*()——+_)(*&^%$#@!~?><:"}{|、】【';、。,'.]/g, '');
// return; return;
// } }
handleInput(e.target.value) handleInput(e.target.value)
} }
@@ -995,8 +995,7 @@ const changeBackText = (e: any) => {
} }
const validateInput = (input: string) => { const validateInput = (input: string) => {
// 正则说明:只允许字母(大小写)、数字、中文和空格 const regex = /^[a-zA-Z0-9\u4e00-\u9fff\u3040-\u309f\u30a0-\u30ff\uac00-\ud7a3\u00c0-\u017f\s~!@#¥%……&*()——+_)(*&^%$#@!~?><:"}{|、】【';、。,'.]+$/;
const regex = /^[a-zA-Z0-9\u4e00-\u9fa5\s]+$/;
return regex.test(input); return regex.test(input);
} }