2014年3月10日 星期一

LAB 7

<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 = /^[A-Za-z\d]{6,}$/;
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 = "passwords need to be 6 characters long and consist of uppercase characters, lowercase characters, and digits only."
notify.id="notify";
var body = document.getElementById("body");
body.appendChild(notify);
}
}
};
</script>
</html>
大於6個字

小於6個字

沒有留言:

張貼留言