javascript参数问题,急(有关正则)
<input type= "button " onclick= "CheckExists(document.all.abc,2,10); "/>
<script type= "text/javascript ">
function CheckExists(obj,minSize,maxSize)
{
alert(minSize);
alert(maxSize);
var pattern = /^[a-zA-Z]{1}[a-zA-Z0-9_]{minSize,maxSize}$/;
if (pattern.test(obj.value))
alert( "true ");
else
alert( "false ");
}
</script>
打印是打出来了,但是minSize,maxSize始终起不了作用,
就是说不管我输入的是否正确,始终显示false
------解决方案--------------------你 alert(pattern);
就明白了,另外比较用这个
if (pattern.test(obj))
------解决方案--------------------var pattern = new RegExp( "^[a-zA-Z]{1}[a-zA-Z0-9_]{ " + minSize ", " + maxSize + "}$ ");
hehe,小问题