1.添加简单的正则:eg1.密码至少6位数,eg2.两次密码不一致; 当没满足的时候时候都是通过弹窗弹出来提示的;
2.当提交的时候,如果有一个input框没输入也用弹框弹出来提示
3.谢谢了各位路过的好汉、妹子,满意还会追加积分谢谢!!!
里面有一个限制长度的,长度不够就提交不了,可以自行修改,要匹配正则,同理
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<form>
<table align="center">
<tr>
<td>用 户 名:</td>
<td><input type="text" name="username" id="name" onchange="test2()"/></td>
</tr>
<tr>
<td>密 码:</td>
<td><input type="password" name="pwd1" id="pwd1" onchange="test()" /></td>
</tr>
<tr>
<td>确认密码:</td>
<td><input type="password" name="pwd2" id='pwd2'/ onchange="test1()"></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="提交" onclick="myfunction()" />
<input type="reset" value="清空" /></td>
</tr>
</table>
</form>
<script type="text/javascript">
function myfunction(){
var a=document.getElementById("name").value;
var x=document.getElementById("pwd1").value;
var y =document.getElementById("pwd2").value;
if(a!=null&&a!=""&&x!=null&&x!=""&&y!=null&&y!=""){
return true;
}
return false;
}
function test(){
var x=document.getElementById("pwd1").value;
//x就是密码的字符串,用到正则,在这里对字符串匹配就行,一样的返回true 或false
if(x.length<6){
alert("密码不能少于六位数!");
return false;
}
return true;
}
function test1(){
var x=document.getElementById("pwd1").value;
var y =document.getElementById("pwd2").value;
if(y!=x){
alert("两次密码不一致!");
return false
}
return true
}
function test2(){
var a=document.getElementById("name").value;
if(a!=""&&a!=null){
return true;
}
return false;
}
window.onsubmit=function(){
if(test()&&test1()&&myfunction()&&test2()){
alert('注册成功');
return true;
}
return false;
}
</script>
</body>
</html>
密码长度大于等于6,两次密码相同,不为空,刚好帮人做了一个。
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<form>
<table align="center">
<tr>
<td>用 户 名:</td>
<td><input type="text" name="username" id="name" /></td>
</tr>
<tr>
<td>密 码:</td>
<td><input type="password" name="pwd1" id="pwd1" onchange="test()" /></td>
</tr>
<tr>
<td>确认密码:</td>
<td><input type="password" name="pwd2" id='pwd2'/ onchange="test1()"></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="提交" onclick="myfunction()" />
<input type="reset" value="清空" /></td>
</tr>
</table>
</form>
<script type="text/javascript">
function myfunction(){
var a=document.getElementById("name").value;
var x=document.getElementById("pwd1").value;
var y =document.getElementById("pwd2").value;
if(a!=null&&a!=""&&x!=null&&x!=""&&y!=null&&y!=""){
return true;
}
return false;
}
function test(){
var x=document.getElementById("pwd1").value;
if(x.length<6){
alert("密码不能少于六位数!");
return false;
}
return true;
}
function test1(){
var x=document.getElementById("pwd1").value;
var y =document.getElementById("pwd2").value;
if(y!=x){
alert("两次密码不一致!");
return false
}
return true
}
window.onsubmit=function(){
if(test()&&test1()&&myfunction()){
alert('注册成功');
return true;
}
return false;
}
</script>
</body>
</html>
<script>
function check(f) {
if (f.pwd.value == '') { alert('请输入密码!'); f.pwd.focus(); return false }
if (f.pwd.value.length < 6) { alert('密码长度6位!'); f.pwd.select(); return false }
if (f.cpwd.value == '') { alert('请输入确认密码!'); f.cpwd.focus(); return false }
if (f.cpwd.value != f.pwd.value) { alert(' 密码和确认密码不一致!'); f.cpwd.select();return false}
}
</script>
<form onsubmit="return check(this)">
密 码:<input type="password" name="pwd" /><br />
确认密码:<input type="password" name="cpwd" />
<input type="submit" value="保存" />
</form>
写这么多建议直接网上搜tip插件,档下来用就行了。。。
<!doctype html>
<script>
function check(f) {
var s = '';
if (f.pwd.value == '') s += '<br>请输入密码!';
if (f.pwd.value.length < 6) s += '<br>密码长度大于6位!';
if (f.cpwd.value == '') s += '<br>请输入确认密码!';
if (f.cpwd.value != f.pwd.value) s += '<br>密码和确认密码不一致!';
if (s != '') {
art.dialog({ content: s.replace('<br>', ''), lock: true });
return false
}
}
</script>
<script src="http://lab.seaning.com/artDialog.source.js?skin=default"></script>
<link rel="stylesheet" type="text/css" href="http://lab.seaning.com/skins/default.css?4.1.7" />
<form onsubmit="return check(this)">
密 码:<input type="password" name="pwd" /><br />
确认密码:<input type="password" name="cpwd" />
<input type="submit" value="保存" />
</form>