我想在輸入時驗證客戶端的密碼,方法是更改密碼提示與給定密碼的有效性。在編碼/服務器端,我已經添加了驗證和它的工作。在客戶端,我想提醒用戶使用提示。如何更改(打勾)輸入密碼時驗證密碼的提示?
例只是如何我想:
我想改變glyphicon刪除圖標到OK一旦滿足密碼的驗證。這只是告訴用戶他們的密碼可以有效或無效的用戶指令。下面
<div class="row" style="text-align:left; font-weight:bold ; color:navy;">
Password Hint:
</div>
<div class="row" style=" color:black; margin:10px 0px">
<span id="Length" class="glyphicon glyphicon-remove" style="font-weight:bold;color:red "></span> Minimum 6 digits
<br /><span id="UpperCase" class="glyphicon glyphicon-remove" style="font-weight:bold;color:red "></span> Atleast 1 upper case letters (A – Z)
<br /><span id="LowerCase" class="glyphicon glyphicon-remove" style="font-weight:bold;color:red "></span> Atleast 1 Lower case letters (a – z)
<br /><span id="Numbers" class="glyphicon glyphicon-remove" style="font-weight:bold;color:red "></span> Atleast 1 number (0 – 9)
<br /><span id="Symbols" class="glyphicon glyphicon-remove" style="font-weight:bold;color:red "></span> Atleast 1 non-alphanumeric symbol (e.g. ‘@@Z$%£!’)
</div>
腳本:下面
代碼
<script type="text/javascript" >
$(function() {
$("#NewPassword").bind("keyup", function() {
var regex1 = new Array();
var regex2 = new Array();
var regex3 = new Array();
var regex4 = new Array();
regex1.push("[A-Z]"); //Uppercase Alphabet.
regex2.push("[a-z]"); //Lowercase Alphabet.
regex3.push("[0-9]"); //Digit.
regex4.push("[[email protected]@#$%^&*]"); //Special Character.
if ($(this).val().length<6) {
$('#Length').removeClass("glyphicon glyphicon-remove").addClass("glyphicon glyphicon-ok ");
}
for (var i = 0; i < regex1.length; i++) {
if (new RegExp(regex[i]).test($(this).val())) {
$('#UpperCase').removeClass("glyphicon glyphicon-remove").addClass("glyphicon glyphicon-ok ");
}
}
for (var i = 0; i < regex2.length; i++) {
if (new RegExp(regex[i]).test($(this).val())) {
$('#LowerCase').removeClass("glyphicon glyphicon-remove").addClass("glyphicon glyphicon-ok");
}
}
for (var i = 0; i < regex3.length; i++) {
if (new RegExp(regex[i]).test($(this).val())) {
$('#Numbers').removeClass("glyphicon glyphicon-remove").addClass("glyphicon glyphicon-ok");
}
}
for (var i = 0; i < regex4.length; i++) {
if (new RegExp(regex[i]).test($(this).val())) {
$('#Symbols').removeClass("glyphicon glyphicon-remove").addClass("glyphicon glyphicon-ok");
}
}
});
});
</script>
我的密碼文本框ID爲 「新密碼」。但我上面的編碼不起作用。我只有顯示器,但沒有工作。
如果在事件處理程序中放置console.log函數,會發生什麼?它是否向控制檯寫入任何內容?只要檢查你的處理程序是否正在運行 –
sory我不明白你說什麼,因爲我是新的MVC我試着用谷歌和一切只。我也很困惑我的編碼是否正確? – Halim
所以在你的keyup事件處理程序中,就在你定義你的數組變量之前,把一個console.log('test');線。當你開始輸入你的密碼字段時,你在瀏覽器開發工具的控制檯窗口中看到「測試」了嗎? –