前端常用的正则表达式(代码实例)

  匹配 正整数 || null

  function checkNumber(theObj) {

  var reg=/^[1-9]\d*$|null/;

  if (reg.test(theObj)) {

  return true;

  }

  return false;

  }

  匹配 整形 || 小数 || null

  function checkNumber(theObj) {

  var reg=/[1-9]\d*.\d*|0.\d*[1-9]\d*|null/;

  if (reg.test(theObj)) {

  return true;

  }

  return false;

  }

  匹配 国内手机号码

  function checkNumber(theObj) {

  var reg=/0?(13|14|15|17|18|19)[0-9]{9}/;

  if (reg.test(theObj)) {

  return true;

  }

  return false;

  }

  匹配 身份证号码

  function checkNumber(theObj) {

  var reg=/\d{17}[\d|x]|\d{15}/;

  if (reg.test(theObj)) {

  return true;

  }

  return false;

  }

  匹配 邮箱地址

  function checkNumber(theObj) {

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

  if (reg.test(theObj)) {

  return true;

  }

  return false;

  }

  匹配 匹配用户名

  function checkNumber(theObj) {

  var reg=/[A-Za-z0-9_\-一-龥]+/;

  if (reg.test(theObj)) {

  return true;

  }

  return false;

  }

posted @ 2022-02-23 18:01  ebuybay  阅读(68)  评论(0编辑  收藏  举报