2014年3月11日 星期二

Using browsers for programming II

結果圖:

<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_]+[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 = "長度必須至少六個字元,且必須至少包含一個數字以及一個非英文字母的字元"
notify.id="notify";

var body = document.getElementById("body");
body.appendChild(notify);
}
}
};

</script>
</html>

1 則留言: