html5表单验证(Bootstrap)
邮箱验证:
<input name="email" type="text" placeholder="必填项" class="input-xlarge" required pattern="^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$"
title="邮箱正确格式:xxx@xxx.xxx">
密码验证:
<div class="control-group">
<label class="control-label">
密码</label>
<div class="controls">
<input id="pwd" name="pwd" type="password" placeholder="必填项" class="input-xlarge"
required onchange="checkPasswords()">
</div>
</div>
<div class="control-group">
<label class="control-label">
确认密码</label>
<div class="controls">
<input id="pwd1" name="pwd1" type="password" placeholder="必填项" class="input-xlarge"
required onchange="checkPasswords()">
</div>
</div>
验证方法:
<script>
function checkPasswords() {
var passl = document.getElementById("pwd");
var pass2 = document.getElementById("pwd1");
if (passl.value != pass2.value)
passl.setCustomValidity("两次密码必须输入一致!");
else
passl.setCustomValidity('');
}
function check() {
document.getElementById('ok').disabled = 'disabled';
}
</script>