1、短信模板内容
验证码 ${username} 12345
验证码 ${username} 12345
验证码 ${username} 12345
验证码 ${username} 12345
验证码 ${username} 12345
验证码 ${username} 12345从代码中提取 username, 并判断验证码 username中只存在英文字母2、内容校验,提取模板中${}的内容并且,内容只能使用英文
smsTemplateContentChange(value){

// 短信模板内容 校验

const error = this.smsTemplateForm.get('templateContent').getError('pattern');

if (error){

return;

}else{

this.smsTemplateForm.get('templateContent').setErrors(null);

}

const reg = /\$\{((?!\{).)*\}/g;

const matchStr = value.match(reg);

const resultList = new Set();

this.paramsList = new Set();

const pattern = '^[a-zA-Z]{1,}$';

const regex = new RegExp(pattern);

let isError = false;

if (matchStr){

matchStr.forEach((item: string) => {

const result = item.replace('${', '').replace('}', '');

if (!result.match(regex)){

isError = true;

}

resultList.add(result);

});

if (isError){

// 设置错误信息

this.smsTemplateForm.get('templateContent').setErrors({errorParams: '参数只能使用英文'});

}else{

this.paramsList = resultList;

}


}

// console.log(value.match(reg).replace('${', '').replace('}', ''));

}
smsTemplateContentChange(value){

// 短信模板内容 校验

const error = this.smsTemplateForm.get('templateContent').getError('pattern');

if (error){

return;

}else{

this.smsTemplateForm.get('templateContent').setErrors(null);

}

const reg = /\$\{((?!\{).)*\}/g;

const matchStr = value.match(reg);

const resultList = new Set();

this.paramsList = new Set();

const pattern = '^[a-zA-Z]{1,}$';

const regex = new RegExp(pattern);

let isError = false;

if (matchStr){

matchStr.forEach((item: string) => {

const result = item.replace('${', '').replace('}', '');

if (!result.match(regex)){

isError = true;

}

resultList.add(result);

});

if (isError){

// 设置错误信息

this.smsTemplateForm.get('templateContent').setErrors({errorParams: '参数只能使用英文'});

}else{

this.paramsList = resultList;

}


}

// console.log(value.match(reg).replace('${', '').replace('}', ''));

}3、前端html




提取可用参数:{{tag}}



 



提取可用参数:{{tag}}


4、最终效果