我需要包含密码验证是至少8个字符包括一个特殊字符和至少一个大写字母。在javascript中的密码验证
我已经尝试了这个脚本:
$(document).on('keyup', '.passworduser', function() {
var txtInput = $(this).val();
var regPass = "^(?=.*?[0-9])(?=.*?[A-Z])(?=.*?[#[email protected]$%^&*-_]).{8,}$";
var color = "Red";
if (txtInput.length > 7) {
if (!txtInput.match(regPass)) {
$('#password_strength').html("Include a special character and at least one capital letter");
$("#password_strength").css("color", color);
} else {
$('#password_strength').html("");
}
} else {
$('#password_strength').html("Password to be a minimum of 8 characters");
$("#password_strength").css("color", color);
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" class="passworduser">
<div id="password_strength"></div>
对于一些表达它的工作,对一些人来说并非如此。
*对于某些表达它正在工作,对于一些它不是。* =>你能澄清吗?此外,你会惊讶什么'[* -_]'做... –
@托马斯:包括下划线和减号,如果用户想添加这就是我已经使用。 – heema
查看Tushar关于char类中连字符语义的回答。请参阅[demo](https://regex101.com/r/VX08iT/1) –