2.判断用户名是否合法:用户名要求长度必须在6~10之间,并且不允许出现敏感词admin的任何大小写形式。按提交进行判断,如果不正确,请弹出“格式错误,请重新输入”,否则,弹出“恭喜您,该用户名能使用”。
用户名
<input type="button" id="check" value="提交" />2.判断用户名是否合法:用户名要求长度必须在6~10之间,并且不允许出现敏感词admin的任何大小写形式。按提交进行判断,如果不正确,请弹出“格式错误,请重新输入”,否则,弹出“恭喜您,该用户名能使用”。
用户名
<input type="button" id="check" value="提交" />代码:
<title>Title</title>
用户名
<input type="text" id="username" />
<input type="button" id="check" value="提交" />
<script>
document.getElementById("check").addEventListener("click", function() {
var username = document.getElementById("username").value;
var illegal = /admin/i.test(username);
if (username.length < 6 || username.length > 10 || illegal) {
alert("格式错误,请重新输入");
} else {
alert("恭喜您,该用户名能使用");
}
});
</script>