CreateTime--2017年9月6日09:10:19

Author:Marydon

思路:

  1.判断字符串中是否包含中文;

  2.存在中文时,过滤掉。

举例:

var fileName = ",测试123";
// 过滤掉文件名中的中文(也包含日文和韩文),不包含中文符号
var regex = /[\u4E00-\u9FA5\uF900-\uFA2D]/;
// 包含中文
if (regex.test(fileName)) {
    // 用于临时存储单字符
    var chinese = "";
    // 用于校验是否是中文
    var flag = false;
    // 用于存储过滤后的文件名
    var filterChinese = "";
    for (var i=0; i < fileName.length; i++) {
        chinese = fileName.substring(i, i+1);
        flag = regex.test(chinese);
        // 该字符不是中文
        if(!flag) {
            filterChinese += chinese;
        }
    }
    // 过滤掉中文后的文件名
    fileName = filterChinese;
}
alert(fileName);// ,123

 

 相关推荐:

 

 

相关文章:

  • 2022-12-23
  • 2021-06-27
  • 2021-12-19
  • 2022-12-23
  • 2021-06-21
  • 2021-10-16
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-02-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案