View Single Post
  #1  
Old 09-05-2009
c0sie c0sie is offline
*SuPeRsTaR mEmBeR*
 
Join Date: Feb 2006
Location: Cheltenham
Posts: 3,294
Question Anyone care to help me debug my crappy JavaScript please?

I have to produce a webpage that uses a while{} to ensure that a valid password is entered into a prompt box. Valid passwords include atleast 6 characters, include a @ and begin with the number 0.

Any ideas?

Thanks in advance!!

Code:
<html>
<head>

<script language = "JavaScript">

//Declare and initilise variables
	var intIncludesAt = 0;
	var strPassword = prompt("Please enter a valid password","");
	var intFirstChar;
	var intValidPassword = 0;
	var strCharCheck;

	function validatePassword()
	{
		while(intValidPassword == 0)
		{ 	
			intFirstChar = parseInt(strPassword.charAt(0));
		
			for (intCount=0; intCount<strPassword.length; intCount++)
			{
				if(strPassword.charAt(intCounter) == @)
				{
					intIncludesAt = 1;
				}
			}
		
		if (strPassword.length >= 6 && intintFirstChar == 0 && intIncludesAt == 1)
		{
			intValidPassword = 1;
		}
	}

</script>

</head>

<body>

<input type="button" value="Click here to validate your password" name="cmdValidatePassword" onclick = "validatePassword()">
</body>

</html>
__________________
Previously:
BRCA Micro Section Chairman.
BRCA Micro National Champion.

Currently:
JQ fan.
Bellend.

Forums are better than Facebook groups
Reply With Quote