验证用户名,要求 1、不能为空 2、不能小于6位数大于20位数 3、首字母不能大写

<body>
  <input type="text" id="username" />
  <p id="info"></p>
</body>

<script>
  var username = document.getElementById("username");
  var info = document.getElementById("info");
  username.onblur = function(){
  info.innerText = "";
  if(!username.value){
  info.innerText = "用户名不能为空";
  }
  if((username.value.length>0 && username.value.length<6) || username.value.length>20){
  info.innerText = "用户名不合法";
  }
  if(username.value.charCodeAt(0)>=65 && username.value.charCodeAt(0)<=90){
  info.innerText = "首字母不能大写";
  }
  }

</script>

posted @ 2019-04-09 22:21  泽东玩乾坤  阅读(950)  评论(0编辑  收藏  举报