Disclaimer: This article is a blogger original article, please indicate the source. https://blog.csdn.net/qq_42968609/article/details/85318784
Recent projects have involved not enter special characters check rules are as follows:
The use of 去除特殊字符
regular expressions is:
// 英文校验规则
// -------------!!!注意:转义特殊字符'-'
const regEn = /[`~!@#$%^&*()_\-+=<>?:"{},.\\/;'[\]]/im
// 中文校验规则
const regCn = /[·!#¥(——):;“”‘、,|《。》?、【】[\]]/im
Verify Code:
const regEn = /[`~!@#$%^&*()_+-=<>?:"{},.\\/;'[\]]/im
const regCn = /[·!#¥(——):;“”‘、,|《。》?、【】[\]]/im
const validateTaskName = (rule, value, callback) => {
if (!value) {
return callback(new Error('任务名称不能为空'))
}
if (regEn.test(value) || regCn.test(value)) {
callback(new Error('任务名称不允许特殊字符'))
} else {
callback()
}
}