In my class, I need to develop a simple JavaScript form for the user to input alphabetic characters, and than check to see if both Uppercase and Lowercase characters are used. This is what I have so far for the code, but I'm completely lost on why it's not working the way I need it to. Below are the exact instructions, I'm not looking for you to complete my code, just give me a few hints on where to go with this.
Write a JavaScript program that ensures that user input contains only upper or lower case letters by using the String object and the RegEx object (regular expression).
Construct a regular expression using the RegEx object that checks for upper or lower case letters only. Add the JavaScript statements.
Add the JavaScript statement to accept text input from the user.
Add the JavaScript statement, and use either the search() or match() methods to check the input string and then write the answer to the screen.
<script type="text/JavaScript">function chkPwd() {var pwd = document.form1.pwd;var pwdMsg = document.getElementById('pwdMsg'); regex = /[A-Z]/;var pwd1 = pwd.value;if(pwd1.search(regex -- -1)) {pwdMsg.innerHTML = "Must contain at least one uppercase character"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>
Thanks!