日期:2014-05-20 浏览次数:20915 次
String regex = "[0]{3}[1-9]|[0]{2}[1-9][0-9]|[0][1-9][0-9]{2}|1[0-9]{3}|2[0-4][0-9]{2}|2500";
for (int i=1; i<3000; i++) { //check
String s = String.format("%04d", i);
if (! s.matches(regex)) {
System.out.println(i);
break;
}
}
------解决方案--------------------
<script>
var str = "30001";
if(/^([0-1][0-9][0-9][0-9])|(2[0-4][0-9][0-9])|(2500)$/.test(str))
{
document.write('yes');
}
else
{
document.write('no');
}
</script>