87,904
社区成员
发帖
与我相关
我的任务
分享
<body>
</form>
<form method="post" action=""id="allow">
<div id="form">
<div class="int">
<label for="username">用户名:</label>
<input type="text" id="username" class="input" reg="^[a-zA-Z0-9]{2,8}$" tip="用户名是1-8位不得使用_+!@#$d"/>
</div>
<div class="int">
<label for="txtpwd">密 码:</label>
<input type="password" id="txtpwd" class="input" reg="^[a-zA-Z0-9]{6,16}$" tip="密码由英文字母和数字字符组成!"/>
</div>
<br>
<input type="submit" value="提交" id="send" />
</form>
</body>
</html>
<form method="post" action=""id="allow">
<div id="form">
<div class="int">
<label for="username">用户名:</label>
<input type="text" id="username" class="input" reg="^[a-zA-Z0-9]{2,8}$" tip="用户名是1-8位不得使用_+!@#$d"/>
</div>
<div class="int">
<label for="txtpwd">密 码:</label>
<input type="password" id="txtpwd" class="input" reg="^[a-zA-Z0-9]{6,16}$" tip="密码由英文字母和数字字符组成!"/>
</div>
<br>
<input type="submit" value="提交" id="send" />
</form>
<script>
var t=document.getElementById('send');
t.disabled=true;
var u=document.getElementById('username');
var p=document.getElementById('txtpwd');
function f(){
if(!u.value)return t.disabled=true;
if(!new RegExp(u.getAttribute('reg')).test(u.value)){ t.disabled=true;return alert(u.getAttribute('tip'));}
if(!p.value)return t.disabled=true;
if(!new RegExp(p.getAttribute('reg')).test(p.value)) {t.disabled=true;return alert(p.getAttribute('tip'));}
t.disabled=false;
}
u.onblur=f;p.onblur=f;
</script>
<script>
function check(f) {
if (!new RegExp(f.username.getAttribute('reg')).test(f.username.value)) { alert(f.username.getAttribute('tip')); f.username.focus(); return false }
if (!new RegExp(f.txtpwd.getAttribute('reg')).test(f.txtpwd.value)) { alert(f.txtpwd.getAttribute('tip')); f.txtpwd.focus(); return false }
}
</script>
<form method="post" action="" id="allow" onsubmit="return check(this)">
<div id="form">
<div class="int">
<label for="username">用户名:</label>
<input type="text" id="username" name="username" class="input" reg="^[a-zA-Z0-9]{2,8}$" tip="用户名是1-8位不得使用_+!@#$d"/>
</div>
<div class="int">
<label for="txtpwd">密 码:</label>
<input type="password" id="txtpwd" name="txtpwd" class="input" reg="^[a-zA-Z0-9]{6,16}$" tip="密码由英文字母和数字字符组成!"/>
</div>
<br>
<input type="submit" value="提交" id="send" />
</form>