2014年3月17日 星期一

lab13

<html> <head> </head> <body id="body"> <form action="javascript:void(0);" id="exampleForm"> <input id="examplePass" type="text" /> <input type="submit" /> </form> <script> document.getElementById("exampleForm").onsubmit = function(){ var passwordRegex =/^((?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))*$/; if(!passwordRegex.test(document.getElementById("examplePass").value)){ console.log("Regex didn't match"); var notify = document.getElementById("notify"); if(notify === null){ notify = document.createElement("p"); notify.textContent = "請輸入正確的網址"; notify.id ="notify"; var body =document.getElementById("exampleForm"); body.appendChild(notify); } } }; </script>

沒有留言:

張貼留言