求大神赐教js!
需求:输入密码的同时就会判断密码的格式和位数,发现格式不对会提示.但是此时不会判断位数,只有位数超了才会提示。
,并且不能继续输入。而不是鼠标点击或者移开触发。
位数用maxlength控制就行了,只需要判断格式就行了,什么格式自己在oninput onpropertychange中判断
<input type="password" oninput="checkPwd(this)" onpropertychange="checkPwd(this)" maxlength="10" />
<script>
function checkPwd(el) {
if (检查el.value格式的判断代码) {
alert('格式不对!'); el.select();
}
}
</script>
长度限制 直接用 maxlength属性 输入判断用 oniput事件!
<input type="password" id="pwd" required oninput="ckeckpwd();" min-length="6" maxlength="20" placeholder="6-20位,由数字,字母,_,@组成">
<script>
function checkPwd() {
var reg = /^[0-9a-zA-Z_@]{6-20}$/
if (reg.test($("#pwd").val())) {
alert('格式不对!');
}
}
</script>
<input type="password" id="pwd" required oninput="ckeckpwd();" min-length="6" maxlength="20" placeholder="6-20位,由数字,字母,_,@组成">
<script>
function checkPwd() {
var reg = /^[0-9a-zA-Z_@]{6-20}$/
if (!reg.test($("#pwd").val())) {
alert('格式不对!');
}
}
</script>