一个重置密码html示例

<style type="text/css">
    .formblock {
        display: inline-block;
        padding: 0px 6px;
        min-width: 300px;
        border: solid 1px #000;
        background-color: #ccc;
    }
    .formblock input {margin-bottom: 10px; }
</style>

<form method="post" action='varify.php' >
    <div class="formblock">
        <h2>reset password</h2>
        <label>Username:<br><input type="text" name="username" value="username" readonly></label><br><!-- value处设置用户名,(比如用PHP),此项只读不可修改  -->
        <label>Password:<span style="color: red;" id="passwdText"></span><br>
            <input type="password" name="passwd1" oninput="testPw()" minlength="8" pattern="^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$" title="At least 8 characters and contains numeric uppercase and lowercase letters" required></label><br>
        <label>Confirm Password:<span style="color: red;" id="confirmText"></span><br>
            <input type="password" name="passwd2" oninput="confirmPw()" minlength="8" pattern="^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$" title="At least 8 characters and contains numeric uppercase and lowercase letters" required></label><br>
        <input type="submit" value="reset">
    </div>
</form>

<script type="text/javascript">
    var in_password1 = document.querySelector("input[name=passwd1]");
    var span_testpw = document.querySelector("span#passwdText");
    var in_password2 = document.querySelector("input[name=passwd2]");
    var span_confirm = document.querySelector("span#confirmText");
    //var btn_sub = document.querySelector("input[type=submit]");
    var pattern = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$/;
    function testPw(){
        if(in_password1.value == ""){
            span_testpw.innerHTML = "not null";
            return;
        }
        if(pattern.exec(in_password1.value)){
            span_testpw.innerHTML = "";
        } else {
            span_testpw.innerHTML = "At least 8 characters and contains numeric uppercase and lowercase letters";
        }
    }
    function confirmPw(){
        if(in_password1.value === in_password2.value){
            span_confirm.innerHTML = "";
            in_password2.setCustomValidity('');
        } else {
            span_confirm.innerHTML = "Passwords do not match";
            in_password2.setCustomValidity("Passwords do not match");
        }
    }
</script>

文中的正则表达式来自:博客园-RyanAce1988

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

今夕何夕2112

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值