常用正则表达式积累

  1、验证中文和英文:

  let pattern = /^[a-zA-Z\u4e00-\u9fa5]+$/

  let str = ''

  console.log(pattern.test(str))

 

  2、验证手机号码:

  let pattern = /^[1][3,4,5,7,8][0-9]{9}$/

  let str = ''

  console.log(pattern.test(str))

 

  3、验证身份证:

  let pattern = /\d{17}[0-9Xx]|\d{15}/g,

  let str = '';

  console.log(pattern.test(str));

  

  4、验证邮箱:

  var pattern = /\w[-\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\.)+[A-Za-z]{2,14}/g,

  let str = '';

  console.log(pattern.test(str));

  

  5、验证正整数:

  var pattern = /^[1-9]\d*$/g,

  let str = ''; 

  console.log(pattern.test(str));

 

  6、验证中文姓名:

  /^([\u4e00-\u9fa5·]{2,10})$/

 

  7、千分制(每三位加一个逗号) 

function thousandSystem (str) {
  return str.replace(/\d{1,3}(?=(\d{3})+$)/g, function (s) {
    return s + ','
  })
}

 

  

 

posted @ 2018-09-14 11:08  江峰★  阅读(261)  评论(0编辑  收藏  举报