我正在使用这个脚本,它使用户有必要使用大写字母和小写字母
<input title="Password must contain at least 6 characters, including UPPER/lowercase and numbers" type="password" required pattern="(?=.*'d)(?=.*[a-z])(?=.*[A-Z]).{6,20}" maxlength="20" name="password" onchange="
this.setCustomValidity(this.validity.patternMismatch ? this.title : '');
if(this.checkValidity()) form.confirm_password.pattern = this.value;
" placeholder="Password"/>
<input title="Please enter the same Password as above" type="password" required pattern="(?=.*'d)(?=.*[a-z])(?=.*[A-Z]).{6,20}" name="confirm_password" onchange="
this.setCustomValidity(this.validity.patternMismatch ? this.title : '');" placeholder="Confirm Password" maxlength="20" id="confirm_password">
我不想为这个目的使用额外的java脚本。我希望用户可以输入一个特殊字符或者大写字母
所以任何人都可以帮助我提供一个好的正则表达式,满足我的要求。这是
- 大写字母(A-Z)(不需要但允许)
- 小写字母(a-z)(必要)
- 数字(0-9)(必要)
- 专用书信(! @ # $ % ^,*>
如果需要,可以尝试使用更多验证。<>之前函数CheckPassword(inputtext) {Var error = ";var ltnous =/^'w+$/;var No =/[0-9]/;var UC =/[A-Z]/;var match =/^[A-Za-z0-9_@./#&+-]*$/;If (inputtext == ") {alert('密码不能为空');返回错误;}If (!match.test(inputtext)) {密码只能包含字母、数字&强调");返回错误;}if (!No.test(inputtext)) {alert('密码必须至少有1个数字');返回错误;}if (!UC.test(inputtext)) {alert('密码必须包含至少1个大写字母');返回错误;}如果(inputtext。长度& lt;4) {alert('密码太短');返回错误;}如果(inputtext。长度> 16){alert('密码过长');返回错误;}如果(inputtext。长度& lt;5) {警报("弱密码");} else if ((inputtext.)长度> 5)&&(密码。长度& lt;9)) {警报("媒介密码");} else if ((inputtext.)长度>= 9)&&(inputtext。长度& lt;16)) {alert('强密码');}返回true;}
你可以这样做:
<form name="form1" action="#">
<ul>
<li><input type="password" name="pwd1"/></li>
<li> </li>
<li class="submit"><input type="submit" name="submit" value="Submit" onclick="CheckPassword(document.form1.pwd1)"/></li>
<li> </li>
</ul>
</form>
Javascript: function CheckPassword(inputtxt)
{
var passw= /^[A-Za-z]'w{7,14}$/;
if(inputtxt.value.match(passw))
{
alert('Correct, try another...')
return true;
}
else
{
alert('Wrong...!')
return false;
}
}