html 5验证密码和确认密码

时间:2015-10-20 08:05:55

标签: html html5-canvas

如何使用html 5在注册表单中验证密码和确认密码?我知道如何处理java脚本和jquery。但我是html5的新手,所以想用它做。

        <input type="password" placeholder="Password" name="password" id='password1' required>
        <input type="password" placeholder="Confirm Password" name="confirm_password" id="password2" required>

1 个答案:

答案 0 :(得分:4)

你可以试试这个

<input id="password" name="password" type="password" pattern="^\S{6,}$" onchange="this.setCustomValidity(this.validity.patternMismatch ? 'Must have at least 6 characters' : ''); if(this.checkValidity()) form.password_two.pattern = this.value;" placeholder="Password" required>

<input id="password_two" name="password_two" type="password" pattern="^\S{6,}$" onchange="this.setCustomValidity(this.validity.patternMismatch ? 'Please enter the same Password as above' : '');" placeholder="Verify Password" required>