字符串提取 中文、英文、数字

有时候需要判断拿到的字符串包含 中文、英文、数字,

  1. 提取中文 str.replace(/[^\u4E00-\u9FA5]/g,’’)
  1. 提取英文 str.replace(/[^a-zA-Z]/g,’’)
  1. 提取数字 str.replace(/[^\d]/g,’’)

判断是否包含某些字段

str.indexOf("字符") != -1 ? true : false

猜你喜欢

转载自blog.csdn.net/estrusKing/article/details/126139272
今日推荐