v1.0.38: 邮箱/国内手机号/身份证正则格式校验 - 后端validate.php(接入person add/update、duplicate_check账号校验、soft_update、hard_add/convert)前端common.js三函数+person/media/fragment表单提交校验

This commit is contained in:
nanguaboss
2026-08-09 22:58:36 +08:00
parent 4ff4349ef5
commit 3a5cdcdd36
12 changed files with 112 additions and 1 deletions
+5
View File
@@ -138,6 +138,11 @@ function cleanEmail(v) {
return String(v == null ? '' : v).trim();
}
/** 格式校验:邮箱 / 国内手机号 / 身份证 */
function validateEmail(v) { return /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/.test(String(v || '').trim()); }
function validatePhoneCN(v) { return /^1[3-9]\d{9}$/.test(String(v || '').trim()); }
function validateIdCard(v) { return /^\d{15}$|^\d{17}[\dXx]$/.test(String(v || '').trim()); }
/* ============ 会话与权限 ============ */
/**
+1 -1
View File
@@ -5,7 +5,7 @@ var BASE_URL = '/api/';
var PAGE_SIZE = 20;
/** 系统版本号(logo旁展示):修改代码后运行 tools/bump_version.php 自动递增 */
var APP_VERSION = 'v1.0.37';
var APP_VERSION = 'v1.0.38';
/** 页脚版权/备案信息(在 config.js 中修改) */
var FOOTER_TEXT = '© 2026 SuperLink 管理系统 版权所有 | 备案号:请替换为真实备案号';
+10
View File
@@ -253,6 +253,9 @@ $(function () {
if (name) fd[name] = $(this).val();
});
fd.source_type = $('#ha-type').val();
// 格式校验:手机 / 邮箱
if (fd.contact_phone && !validatePhoneCN(fd.contact_phone)) { Dialog.error('手机号码格式不正确(应为国内 11 位手机号,如 13812345678)'); return; }
if (fd.contact_email && !validateEmail(fd.contact_email)) { Dialog.error('邮箱格式不正确'); return; }
httpPost('fragment/hard_add.php', fd).then(function () {
Dialog.success('新增成功', function () {
Dialog.close(idx);
@@ -344,6 +347,9 @@ $(function () {
});
fd.id = id;
fd.target_type = $('#cv-type').val();
// 格式校验:手机 / 邮箱
if (fd.contact_phone && !validatePhoneCN(fd.contact_phone)) { Dialog.error('手机号码格式不正确(应为国内 11 位手机号,如 13812345678)'); return; }
if (fd.contact_email && !validateEmail(fd.contact_email)) { Dialog.error('邮箱格式不正确'); return; }
httpPost('fragment/hard_convert.php', fd).then(function () {
Dialog.success('转换成功', function () {
Dialog.close(idx);
@@ -404,6 +410,10 @@ $(function () {
var name = $(this).attr('name');
if (name) fd[name] = $(this).val();
});
// 格式校验:身份证 / 手机 / 邮箱
if (fd.id_number && !validateIdCard(fd.id_number)) { Dialog.error('身份证号码格式不正确(应为 15 或 18 位)'); return; }
if (fd.phone && !validatePhoneCN(fd.phone)) { Dialog.error('手机号码格式不正确(应为国内 11 位手机号,如 13812345678)'); return; }
if (fd.email && !validateEmail(fd.email)) { Dialog.error('邮箱格式不正确'); return; }
httpPost('fragment/soft_update.php', fd).then(function (res) {
Dialog.success(res && res.is_complete ? '补全完成' : '已保存(整体完整度 ' + (res && res.overall) + '%)', function () {
Dialog.close(idx);
+3
View File
@@ -203,6 +203,9 @@ $(function () {
}
});
if (!data.platform || !data.account_id) { Dialog.error('平台和账号为必填项'); return; }
// 格式校验:平台为手机/邮箱时校验账号格式
if (data.platform === 'phone' && !validatePhoneCN(data.account_id)) { Dialog.error('手机号码格式不正确(应为国内 11 位手机号,如 13812345678)'); return; }
if (data.platform === 'email' && !validateEmail(data.account_id)) { Dialog.error('邮箱格式不正确'); return; }
if (!isEdit && (!data.owner_type || !data.owner_id)) { Dialog.error('归属类型和归属ID为必填项'); return; }
// 录入清洗:手机号去所有空格(含中间),邮箱去首尾空格
if (data.platform === 'phone') data.account_id = cleanPhone(data.account_id);
+5
View File
@@ -419,6 +419,11 @@ $(function () {
});
if (!data.full_name) { Dialog.error('姓名为必填项'); return; }
// 格式校验:身份证 / 手机 / 邮箱
if (data.id_number && !validateIdCard(data.id_number)) { Dialog.error('身份证号码格式不正确(应为 15 或 18 位)'); return; }
if (data.phone && !validatePhoneCN(data.phone)) { Dialog.error('手机号码格式不正确(应为国内 11 位手机号,如 13812345678)'); return; }
if (data.email && !validateEmail(data.email)) { Dialog.error('邮箱格式不正确'); return; }
// 联系方式(手机/邮箱,均为常用)
data.phone = cleanPhone(data.phone);
data.email = cleanEmail(data.email);