Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

password restrictions

Status
Not open for further replies.

Ssanai80

IS-IT--Management
Jun 28, 2001
21
0
0
US
I am making a asp page where my client can request for an id and password. on the requestform, i want to ensure that the client requests a password that has at least one numeric, one upper case, and one lower case characters. How can i use javascript to alert when requested pwd submitted did not meet above requirements?
i thought about converting the input to all caps than match it with original...then samething but convert to small caps...and if there is a match in either case, alert. would that work? and how do i convert input string to caps? or small caps? and how do i check for at least one numeric character?
thank you in advance for all da help
 
I think this will work:
Code:
<html>
<head>
<script>
function check() {
var pw = document.forms[0].pw.value
if (pw.toUpperCase() == pw || pw.toLowerCase() == pw) {
alert(&quot;Field must contain an uppercase and lowercase character.&quot;)
return false
}
if (!(/\d/.test(pw))) {
alert(&quot;Field must contain a number.&quot;)
return false
}
else {
return true
}
}
</script>
</head>
<body>
<form onsubmit=&quot;return check()&quot;>
<input type=&quot;password&quot; name=&quot;pw&quot; />
<input type=&quot;submit&quot; value=&quot;Submit&quot; />
</form>
</body>
</html>
 
thank you very much!! your code worked great!
but why &quot;document.forms(0)&quot;?? i didn't understand that part.
since my form was called &quot;requestform&quot; and the input name was &quot;password&quot;, shouldn't requestform.password.value work?
where did &quot;document&quot; or &quot;forms(0)&quot; come from?
 
forms[0] (square brackets, not parens) refers to the first form in the document. You could also have used document.requestform.password.value
I think he used forms[0] because he wasn't sure if requestform was the name of the form or just a description of it. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top