正则表达式dom
正则表达式dom
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>正则表达式dom</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/bootstrap.css" />
<script type="text/javascript" src="js/jquery-1.11.0.js" ></script>
<script type="text/javascript" src="js/bootstrap.js" ></script>
<style>
form{width:1200px;margin:0 auto;}
#emailTip{display: block;}
h1{text-align: center;}
</style>
<script>
/*测试提示*/
function usershow(){
$('#emailTip').popover('show');
}
function passshow(){
$('#passwordTip').popover('show');
}
/*测试提示结束*/
/*正则表达式*/
/*表单提交检验*/
function submitInput(){
var emailValue=document.getElementById("email").value;
var passwordValue=document.getElementById("password").value;
/*判断用户名和密码是否为空*/
if (emailValue == "" || passwordValue == "") {
return false;
}
}
/*判断邮箱是否合法*/
var checkEmail = function(value){
var reg = /^[a-z\d]+(\.[a-z\d]+)*@([\da-z](-[\da-z])?)+(\.{1,2}[a-z]+)+$/;
if(reg.test(value)){
$('#emailTip').popover('hide');
}else{
$('#emailTip').popover('show');
}
}
/*判断密码是否合法*/
var checkPassword = function(value){
var reg = /^[a-z0-9_-]{6,18}$/;
if(reg.test(value)){
$('#passwordTip').popover('hide');
}else{
$('#passwordTip').popover('show');
}
}
/*正则表达式结束*/
</script>
</head>
<body>
<h1>正则表达式dom</h1>
<form action="#" onsubmit="return submitInput()">
<div class="popover-toggle" title="温馨提示" data-container="body" data-toggle="popover" data-placement="right"
data-content="亲!您输入的邮箱不合法" id="emailTip">
请输入您的邮箱:<input type="text" placeholder="请输入邮箱地址" onblur="checkEmail(this.value)" name="email" id="email" class="form-control" />
</div>
<div class="popover-toggle" title="温馨提示" data-container="body" data-toggle="popover" data-placement="right"
data-content="亲!您输入的密码不合法" id="passwordTip">
请输入您的密码:<input type="password" placeholder="请输入密码" onblur="checkPassword(this.value)" name="password" id="password" class="form-control" />
</div>
<div class="checkbox">
<label>
<input type="checkbox" /> 记住我
</label>
</div>
<button type="submit" class="btn btn-success">登录</button>
<button type="reset" class="btn btn-success">清空</button>
<br><br>
<button onclick="usershow()">显示邮箱的提示</button>
<button onclick="passshow()">显示密码的提示</button>
</form>
</body>
</html>
来源:https://www.cnblogs.com/qypt2015/p/6902029.html