/    Sign up×
Community /Pin to ProfileBookmark

Password check program

i have to create a website that has javascript that inputs a password, and checks for three things:
1)must be at least 8 characters
2)must contain one capital letter
and 3) must contain at least one number.

below is my code so far, but i cant seem to get the alert windows to pop up telling whether or not the password is valid. Any help is greatly appreciated.

[code=php]

<html xmlns=”http://www.w3.org/1999/xhtml” xml:lang=”en” lang=”en”>
<head>
<title>Exam Three Make Up</title>
<script type=”text/javascript”>

<!–
function Start()
{

var password;
var passwordArray = new Array(password.length);
var has8charicters = false;
var numeric = false;
var upperCase = false;

for(var i=0; i<password.length; i++)
{
passwordArray[i] =password.substring(i, i+1);
}

if(password.lenght>=8)
{
has8charicters = true;
numeric = checkNumeric(passwordArray);
upperCase = checkUpperCase(passwordArray);
}
if(has8chariters && numeric && upperCase)
{
alert(“vaild”)
}
else
{
alert(“not vaild”)
}
}

function checkNumeric(anArray)
{

for (var i =0; i<anArray.length; i++)
if(anArray[i]>=”0″ && anArray[i]<=”9″)
return true;
}

function checkUpperCase(anArray)
{

for(var i = 0; i<anArray.lenght; i++)
if(anArray[i]>=”A” && anArray[i]<=”z”)
return true;

}

//–>

</script>
</head>

<body>
<form name=”myForm” onSubmit=”Start()” action = “”>
<p>Please Enter your Password.<br />
<br />
Remember it should contain<br />
<br />
At least one capital letter<br />
<br />
And one number.<br />
<br />

<input name=”password” /> <input type=”Submit” value=”Submit” /></p>
</form>
</body>
</html>

[/code]

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@CharlesNov 19.2006 — &lt;script type="text/javascript"&gt;

String.prototype.isValidPassword = function () {return /.{8}/.test (this) &amp;&amp; /[A-Z]/.test (this) &amp;&amp; /d/.test (this)}

&lt;/script&gt;

&lt;input onchange="if (!this.value.isValidPassword()) {alert (); this.value=''; this.focus()}" type="password"&gt;
Copy linkTweet thisAlerts:
@coop5885authorNov 19.2006 — are you saying thats all the code i need, or is that just some that i am missing. sorry for the stupid questions, im good with java but the script still throws me.

thanks for the reply though
Copy linkTweet thisAlerts:
@CharlesNov 19.2006 — Give it a try as it is.
Copy linkTweet thisAlerts:
@coop5885authorNov 19.2006 — i tried that code, but i still run into the same issue. Whenever i submit it, it clears the text field, and reloads the page, but no alert windows. could it be something in my form?
×

Success!

Help @coop5885 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.11,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...