//http://zhidao.baidu.com/question/322823273.html
<html>
<script>
function showError(){
var uname = document.getElementById("uname").value;
if(uname.length < 5 || uname.length >15){
document.getElementById("error").innerText = "请输入长度在5到15个字符之间的用户名!";
return false;
}else{
document.getElementById("error").innerText = "";
return true;
}
}
</script>
<style>
span{
color:red;
margin-left:5px;
}
</style>
<body>
用户名<input type="text" name="username" id="uname" /><span
id="error"></span><br/>
<button οnclick="showError()">校验!</button>
</body>
</html>