diff --git a/src/views/iot/device/components/DeviceAttributeForm.vue b/src/views/iot/device/components/DeviceAttributeForm.vue index f01bd941..31b3a270 100644 --- a/src/views/iot/device/components/DeviceAttributeForm.vue +++ b/src/views/iot/device/components/DeviceAttributeForm.vue @@ -123,7 +123,8 @@ watch( ) const handleAttributeCodeInput = (val: string) => { - formData.value.attributeCode = val?.replace(/[\u4e00-\u9fa5]/g, '') + const sanitized = (val || '').replace(/[^A-Za-z0-9_]/g, '') + formData.value.attributeCode = sanitized.replace(/^[0-9]+/, '') } @@ -147,6 +148,10 @@ const formRules = reactive({ callback(new Error(t('DataCollection.Device.attributeValidatorCodeNoChinese'))) return } + if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(value)) { + callback(new Error('仅支持英文字母、数字和下划线,且必须以字母或下划线开头')) + return + } callback() }, trigger: ['blur', 'change']