<!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>
</head>
<body>
<h3>登录</h3>
密码:<input type="password" name="" id="passwords"><br /> 邮箱:
<input type="text" name="" id="mailbox" value="" /><br />
<input type="button" id="yz" value="验证信息">
<script type="text/javascript">
document.getElementById("yz").onclick = function() {
var passwords = document.getElementById("passwords").value
var w = /^[0-9a-zA-Z_]{6,}$/
var isPasswords = w.test(passwords)
var mailbox = document.getElementById("mailbox").value
var e = /^[0-9a-zA-Z_]+@[0-9a-zA-Z_]+[\.]{1}[0-9a-zA-Z_]+$/;
var isMailbox = e.test(mailbox)
if (!isPasswords) {
alert("当前密码安全性过低,请重新输入并且长度不小于6")
} else if (!isMailbox) {
alert("邮箱格式不正确")
} else {
alert("登录成功")
}
}
</script>
</body>
</html>
html表单验证
最新推荐文章于 2024-07-09 17:01:34 发布