Home > Backend Development > PHP Tutorial > js中使用正则匹配问题

js中使用正则匹配问题

WBOY
Release: 2016-06-23 14:05:13
Original
954 people have browsed it

我写了一段正则,想在js中匹配,可是使用test、exec后,都不好使,下面是代码,大家帮忙看下


<script> <br /> <br /> function aa(){ <br /> var pattern="/^[1-9]/d*$/"; <br /> var a = "222"; <br /> if(pattern.test(a)){ <br /> alert("成功"); <br /> }else{ <br /> alert("失败"); <br /> } <br /> } <br /> window.onload = aa(); <br /> <br /> </script>

打开页面后,不弹出文本框,啥也没有,怎么回事?


回复讨论(解决方案)

正则写错了
不是 var pattern="/^[1-9]/d*$/";
应该是 var pattern="/^[1-9]\d*$/";

果然,谢谢

正则写错了
不是 var pattern="/^[1-9]/d*$/";
应该是 var pattern="/^[1-9]\d*$/";

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