11.10

// 项目立项表单验证
function validateForm() {
// 1. 验证项目编号(8位数字,前4位年+月,如2410)
const projectId = document.getElementById("projectId").value;
const idReg = /^\d{8}$/;
if (!idReg.test(projectId)) {
alert("项目编号必须为8位数字!");
return false;
}
const yearMonth = projectId.substr(0, 4);
if (yearMonth < "2410" || yearMonth > "9912") {
alert("项目编号前4位需符合“年+月”格式(如2410表示2024年10月)!");
return false;
}

// 2. 验证项目位置(含“省”“市”“区”)
const location = document.getElementById("projectLocation").value;
if (!location.includes("省") || !location.includes("市") || !location.includes("区")) {
    alert("项目位置需符合“XX省XX市XX区XX”格式!");
    return false;
}

// 3. 验证项目名称长度(≤50汉字)
const name = document.getElementById("projectName").value;
if (name.length > 50) {
    alert("项目名称不超过50个汉字!");
    return false;
}

// 4. 验证建设内容长度(≤500汉字)
const content = document.querySelector("textarea[name='constructionContent']").value;
if (content.length > 500) {
    alert("建设内容不超过500个汉字!");
    return false;
}

return true; // 验证通过,提交表单

}

posted @ 2025-11-10 17:04  Cx330。  阅读(3)  评论(0)    收藏  举报