jiangping
2023-08-17 6365ab0a976afdd247742c9b3dca15deb3a7a7a1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
function checkSpecialKey(str) {
  if (str === null || str === undefined || str === "") return true;
  const specialKey = `"[]%_!!~@'#¥%……&*():“;‘。’”+.,*-+|??();、\\^<>{}=/$`
  let reg =  /^[0-9a-zA-Z]+$/
  for (let i = 0; i < str.length; i++) {
    if (specialKey.indexOf(str.substr(i, 1)) === -1 && !reg.test(str[i])) {
      return false;
    }
  }
  return true;
}
 
// 特殊字符交验
export function validateSpecialKey(rule, value, callback) {
  if (!checkSpecialKey(value)) {
    callback(new Error(`只可以输入数字、字母和符号`));
  } else {
    callback();
  }
}