<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
span{
width: 100px;
height: 15px;
display: inline-block;
}
.right{
background-image: url("../Resources/imgs/right.png");
}
.error{
background-image: url("../Resources/imgs/error.png");
}
</style>
</head>
<body>
<input type="text">
<span class=""></span>
<script>
document.querySelector("input").onblur = function (){
this.nextElementSibling.innerHTML = (/^(\w|-){6,16}$/.test(this.value)) ? "正确" : "错误";
}
</script>
</body>
</html>