2013年10月7日 星期一

Lab 8 Using browsers for programming II



輸入純數字
輸入純英文
輸入純符號
等等都錯
至少包含符號跟數字
OKKKKK~~

<html>
<head>
</head>
<body id="body">
<form action="javascript:void(0);" id="exampleForm">
<input type="password" id="examplePass" />
<input type="submit" />
</form>
</body>
<script>
document.getElementById("exampleForm").onsubmit = function(){
var passwordRegex=/^(?=.*[\d])(?=.*[\w]).{6,}$/;
//var passwordRegex= /^[1-9\d]{1,}$/;
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 = "密碼需要至少6碼,包含數字及符號"
notify.id = "notify";
var body = document.getElementById("body");
body.appendChild(notify);
}
}
};
</script>
</html>



沒有留言:

張貼留言