跳到主要内容

验证邮箱是否合法

信息

支持在文本类型的列中检查邮箱是否满足指定的要求,如果满足将在对应的勾选列中标记为 √

实际效果

以下为模拟的示例数据,非真实姓名和邮箱地址

email-checker

源代码

const datasheet = await space.getActiveDatasheetAsync();
const mailField = await input.fieldAsync("请选择邮箱所在列:", datasheet);
const mailFieldId = mailField.id;

const checkField = await input.fieldAsync("请选择校验列,该列需要为勾选类型:", datasheet);
const checkFieldId = checkField.id;

const records = await datasheet.getRecordsAsync();

const mailRule = await input.textAsync('请输入邮箱后缀,例如 @vikadata.com:');
const mailReg = new RegExp(mailRule);
const finalData = [];

for (let record of records) {
const recordId = record.id;
let cellValue = record.getCellValue(mailFieldId);

if (cellValue == null) continue;

const validation = cellValue.match(mailReg);
if (validation != null) {
finalData.push({
id: recordId,
valuesMap: { [checkFieldId]: true }
});
}
}

if (finalData.length) {
await datasheet.updateRecordsAsync(finalData);
}

output.text('完成校验!!!')