JS-regExp-正则表达式匹配2-6的数字

<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <title>Document</title>
 </head>
 <body>
  <script>
		function testReg(){
			var regExp = /^\d{2,6}$/g;
			var input = prompt("请输入2-6位的数字:");
			if(regExp.test(input)){
				alert("格式正确");
			}else{
				alert("格式错误");
			}
		}
	</script>
	<button onclick="testReg()">测试正则表达式</button>
 </body>
</html>

posted @ 2018-11-11 20:21  IndustriousHe  阅读(1326)  评论(0编辑  收藏  举报