0
对于我正在创建的注册表单,我想验证密码,以便用户必须输入包含至少一个大写字母和至少一个数字的密码。如何在用户点击其他地方时验证表单
我已经实现了这个位置: http://jsfiddle.net/k9aHV/1/
<form action="login.php" method="post">
<p><b>UserName:</b> <input type="text" required pattern="\w+" name="fname"/></p>
<p><b>Password:</b> <input type="password" required pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z])\w{6,}" name="password" onblur="this.setCustomValidity(this.validity.patternMismatch ? 'Password must contain at least 6 characters, including UPPER/lowercase and numbers' : '');if(this.checkValidity()) form.password1.pattern = this.value;"></p>
<p><b>Confirm Password:</b> <input type="password" required pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z])\w{6,}" name="password1" onblur="
this.setCustomValidity(this.validity.patternMismatch ? 'Please enter the same password as above' : '');"/></p>
<p><b>Email:</b> <input type="email" name="email"/></p>
<input type="submit"/>
</form>
目前,仅当用户按下提交域的验证。
如何调整我的代码,以便在用户从输入字段中选择或单击时验证代码?
其中setCustomValidity','validity'和其他东西定义'? –
@AshishKumar它在密码输入标签上定义了onblur。 – Kenshin
它没有定义,它在那里被使用。必须有这个函数的定义。 –