运行 ❯
获取您
自身
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <form action="/action_page.php"> Zip code: <input type="text" id="myText" name="zip_code"> <input type="submit"> </form> <p>Click the "Try it" button to specify a regular expression that the text field's value will be checked against. Note that we also set the "title" to describe the pattern.</p> <button onclick="myFunction()">Try it</button> <p id="demo"></p> <script> function myFunction() { document.getElementById("myText").pattern = "[1-3]"; document.getElementById("myText").title = "A number from 1 to 3"; document.getElementById("demo").innerHTML = "The text field can now only contain numbers from 1 to 3."; } </script> </body> </html>