我想要的是如果输入文本框的值是否为格式(1-10号连字符号)我为匹配/^[\d]+([-][\d]+)?$/g but it allows only 0-9(single digits) i not taking 11-20(double digits)
的一个模式执行此操作我需要允许任何类型的数字,如10-11和我怎么能这样做
var txt = document.getElementById("txtShareCount").value;
if(txt.match(/^[\d]+([-][\d]+)?$/g)){
return true;
}
else if(!txt.match( /^[\d]+([-][\d]+)?$/g)){
alert("Pleae Enter Share count this(1-10) format");
document.getElementById("txtShareCount").focus();
return false;
}
else{return true;}
答案 0 :(得分:0)
正则表达式^[\d]+([-][\d]+)?$
完成了你需要的东西