<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<input type="text" name="text" value="" onkeypress="check()" maxlength="12" placeholder="輸入任意內容" id="test"/>
<span id="feedback"></span>
<br /><br />
<input type="button" name="" value="點擊彈出加密後的內容" onclick="showhat();"/>
<script type="text/javascript" src="jquery-2.1.1.js"></script>
<script src="jQuery.md5.js"> </script>
<script type="text/javascript">
var flag = 1;
function check(){
var str = document.getElementById("test").value;
if(str.length < 5){
update("至少輸入5個字符!");
flag = 0;
}else if(str.length > 10){
update("不能超過10個字符!");
str = str.substring(0,10);
document.getElementById("test").value = str.substring(0,10);
flag = 0;
}
else if(str == ""){
flag = 0;
update("無效的用戶名。")
}
else{
flag = 1;
update("有效的用戶名。");
}
}
function update(word){
document.getElementById("feedback").innerHTML = word;
}
function showhat(){
if(flag == 1) {
var youtype = $("#test").val();
alert($.md5(youtype));
}
else
{
document.getElementById("feedback").innerHTML = "請重新輸入";
}
}
</script>
</body>
</html>
正則 onkeydown