作者Kej (comfortably numb)
看板Ajax
标题Re: [问题] 如何动态建立检核用的正规表示式?
时间Sat Mar 10 00:54:20 2007
※ 引述《PTTFHK ()》之铭言:
: function doCheck(num,int,dec){
: var pattern = /^\d{1,int}$|\d{1,int}\.\d{1,dec}$/;
: if(num.match(pattern)==null){
: alert("不符合规定!");
: }else{
: alert("通过检核!");
: }
: }
可以试试改成以下这样:
function doCheck(num,int,dec){
var p = new RegExp("^\\d{1,"+int+"}$|^\\d{1,"+int+"}\\.\\d{1,"+dec+"}$");
if(p.exec(num)==null){
alert("不符合规定!");
}else{
alert("通过检核!");
}
}
--
...the people who are crazy enough to think
they can change the world, are the ones who do...
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 220.133.102.122
1F:推 PTTFHK:酷~ 非常感谢你~^^*(但後来发现需将int改成其他非保留字) 03/10 09:51