<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
span{
width: 100px;
height: 15px;
display: inline-block;
</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>
JavaScript正则表达式验证用户名
最新推荐文章于 2023-11-14 20:16:03 发布