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

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:08:07
Original
1709 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

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));
Copy after login

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

Related labels:
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
Latest Issues
What are JavaScript hook functions?
From 1970-01-01 08:00:00
0
0
0
What is JavaScript garbage collection?
From 1970-01-01 08:00:00
0
0
0
c++ calls javascript
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template