I am trying to validate a user entered password. It can only be letters and numbers and I have to use the match method...even if it isn't the best way...I have to use match(). I am missing something to get the working properly. No number or special characters only letters. I do not know much about javascript.
<script type="text/JavaScript">
function chkPwd() {
var pwd = document.form1.pwd;
var pwdMsg = document.getElementById('pwdMsg');
regex = /[^a-zA-Z]/;
var pwd1 = pwd.value;
if(!pwd1.match(regex)) {
pwdMsg.innerHTML = "Must contain letters only!"
pwd.select();
return;
}else{
pwdMsg.innerHTML = "";
}
}
</script>
</head>
<body>
<form name="form1" action="" method="post">
<p> Password: <br>
<input type="text" name="pwd" onchange="chkPwd()" />
<span id="pwdMsg"></span></p>
<p>
<input type="button" value="chkPass" onclick="chkPwd()">
</p>
</form>
<div id="results"></div>
</body>
</html>
regexbut then usedregxwhich appears to be undefined.