如何在JavaScript验证中组合两个正则表达式

时间:2017-12-30 11:13:26

标签: javascript html css regex

function checkpara(obj) {

  var paragraph = obj.value;
  var para = /\d{4}/;
  if (paragraph.match(para)) {

    document.getElementById("para_error").innerHTML = " You can't use numbers in description";
    document.getElementById("para_error").className = "errmsgshow";
  } else {
    document.getElementById("para_error").className = "errmsghide";
  }

}
.wrapper {
  width: 100%;
  height: 100%;
}

.w_50 {
  width: 400px;
  margin-top: 50px;
  margin-left: 50px;
}

.errmsghide {
  display: none;
}

.errmsgshow {
  display: block;
  color: red;
}
<DOCTYPE! html>
  <html lang="en" xmlns="http://www.w3.org/1999/xhtml">

  <head>
  </head>

  <body>
    <div class="wrapper">
      <div class="container">
        <textarea id="para" name="desc" rows="20" cols="66" onblur="checkpara(this)"></textarea>
        <span id="para_error" class="errmsghide"></span>

      </div>
    </div>

  </body>

  </html>

我使用JavaScript来验证段落。该段不应包含超过4个数字序列(即1234)。

我想要这种格式。 4序列号空间4序列号。 然后它应该显示错误消息。 如何组合两个正则表达式?

1 个答案:

答案 0 :(得分:0)

你需要这个:/\d{4}( \d{4})?/

n 序列:/\d{4}( \d{4})*/

相关问题