javascript - 判断某一个字符串是否完全匹配的正则该怎样写??

WBOY
Release: 2016-06-06 20:08:07
Original
1657 people have browsed it

<code>  <textarea name="val">
   白色:80;黑色:90;绿色:100;红色:-80;
  </textarea>
  <input type="button" value="check">

<script>

// 怎么检测textarea的值完全符合(每一个键值对都需要符合下面这种格式):
     白色:80;
 这种格式??
 
 
</script>
</code>
Copy after login
Copy after login

回复内容:

<code>  <textarea name="val">
   白色:80;黑色:90;绿色:100;红色:-80;
  </textarea>
  <input type="button" value="check">

<script>

// 怎么检测textarea的值完全符合(每一个键值对都需要符合下面这种格式):
     白色:80;
 这种格式??
 
 
</script>
</code>
Copy after login
Copy after login

<code class="javascript">var re = /^([^:\s;]+:-?\d+;)*$/mg;
console.log('白色:60;黑色:50;'.match(re));
console.log('白色:60;;黑色:50;'.match(re));
console.log('蛤蛤:-1;'.match(re));
console.log(''.match(re));</code>
Copy after login

调试在这里 https://regex101.com/r/jK6zG2/2 (会有点慢, 耐心等待加载完)

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template