我希望匹配以7-9开头的任何数字,并且必须只是数字,它可以是任意长度 它工作,但当我只键入一个字符,即7或9 它仍然返回错误
这是我的代码
<!DOCTYPE html>
<html>
<body>
<p>The test() method returns true if it finds a match, otherwise it returns false.</p>
<p>Click the button to search a string for the character "e".</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
var str = "94";
var patt = new RegExp(/^[7-9]\d*/);
var res = patt.test(str);
document.getElementById("demo").innerHTML = res;
}
</script>
</body>
</html>