var pt = /^\d{1,14}(\.\d{1,5})?$/;
if(!pt.test(o)){
return false;
}
如上,如何将14和5改成变量使用??
------解决方案--------------------------------------------------------
- JScript code
<script type="text/javascript"> function test(){ var o = "23655"; var a = 14; var b = 5; //var pt = /^\d{1,iLength}(\.\d{1,dLength})?$/; var pt = /"\d{1,"+a+"}"/; if(!pt.test(o)){ alert("a"); }else{ alert("b"); } }</script>
------解决方案--------------------------------------------------------
上面的写错了。应该是这样
- JScript code
var a = 14; var b = 5; eval("var pt = \/^\\d{1,"+a+"}(\\.\\d{1,"+b+"})?$\/"); if(!pt.test(o)){ return false; }