修改车位车牌号输入限制bug

This commit is contained in:
zhouyanli
2026-08-07 09:24:15 +08:00
parent d44ebd075e
commit 3851aebe66
6 changed files with 68 additions and 65 deletions

View File

@@ -10,7 +10,7 @@
<view class="form-item">
<view class="item-label">车牌号</view>
<input class="item-input" v-model="formData.carNum" placeholder="请输入"
placeholder-class="input-placeholder" maxlength="8" />
placeholder-class="input-placeholder" maxlength="8" @input="onCarNumInput" />
</view>
<view class="form-item">
@@ -155,6 +155,33 @@
uploadUrl: '/api/resident/file/uploadImage'
})
// 车牌号输入限制:省份简称(中文)+ 城市代码(字母)+ 序号(字母数字)
const onCarNumInput = (e) => {
let value = e.detail.value || ''
// 过滤非法字符,只保留中文、大写字母、数字
value = value.replace(/[^一-龥A-Z0-9]/g, '')
// 首字符必须是中文省份简称
if (value.length > 0 && !/^[一-龥]/.test(value)) {
value = value.replace(/[^一-龥]/g, '')
}
// 第二位必须是字母
if (value.length > 1) {
const first = value.charAt(0)
const second = value.charAt(1)
if (!/^[A-Z]$/.test(second)) {
value = first + second.replace(/[^A-Za-z]/g, '').toUpperCase()
}
// 剩余位只允许字母和数字
if (value.length > 2) {
const rest = value.substring(2)
value = value.substring(0, 2) + rest.replace(/[^A-Za-z0-9]/g, '').toUpperCase()
}
}
// 统一转大写
value = value.toUpperCase()
formData.value.carNum = value
}
const inputChange = (typeStr) => {
if (typeStr == '车牌号') {
uni.setStorageSync('carNum', formData.value.carNum)
@@ -182,24 +209,6 @@
icon: "none"
})
}
/* if (!formData.value.carBrand) {
return uni.showToast({
title: "请输入车辆品牌",
icon: "none"
})
}
if (!formData.value.carModel) {
return uni.showToast({
title: "请输入车辆型号",
icon: "none"
})
}
if (!formData.value.carColor) {
return uni.showToast({
title: "请输入车辆颜色",
icon: "none"
})
} */
uni.showLoading({
title: '提交中...',