0
我在javascript中編寫了函數,用於在jsp中進行字母數字密碼驗證,並在文本框的onkeypress事件中調用該函數,但不工作。javascript中的字母數字密碼驗證
function alphanumeric(inputtxt) {
var mypswd = document.getElementById(inputtxt).value;
mypswd = mypswd.trim();
if (mypswd == "" || mypswd == null) {
alert("Please enter password");
} else if (!mypswd.match((/^(?=.\d)(?=.[a-z])(?=.*[A-Z])[0-9a-zA-Z]{8,}$/)) {
alert(" password must be alphanumeric");
}
}
<form name="form1" method="post" action="Register">Username :
<br>
<input type="text" name="uname" onkeypress="return checkSpcialChar(event)" onkeydown=" alphanumeric(inputtxt)" />
<br/>Password :
<br>
<input type="password" name="pwd" onkeypress="return checkSpcialChar(event)" />
<br/>
<br>
<input type="submit" name="action" value="Submit" onsubmit="check()" />
<input type="submit" value="Back" />
</form>
請幫助。
添加一些說明,否則它只是一段代碼... – Dekel