|
#1
|
|||
|
|||
![]()
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 ![]() |
#2
|
|||
|
|||
![]()
So anyways...
This is where im at now: Code:
<script language = "JavaScript"> //Declare and initilise variables var intIncludesAt = 0; //Changes to 1 if an @ sign is found var intFirstChar; //First character of the password var intValidPassword = 0; var intIncludesAt = 0; function validatePassword() { var strPassword = prompt("Please enter a valid password",""); while(intValidPassword == 0) { intFirstChar = parseInt(strPassword.charAt(0)); for (intCount = 0; intCount < strPassword.length; intCount ++) { if(strPassword.charAt(intCount) == "@") { intIncludesAt = 1; } } if (strPassword.length >= 6 && intIncludesAt == 1 && intFirstChar == 0) { intValidPassword = 1; } } if (intValidPassword = 1); alert("Your password is valid!") } </script>
__________________
Previously: BRCA Micro Section Chairman. BRCA Micro National Champion. Currently: JQ fan. Bellend. Forums are better than Facebook groups ![]() |
#3
|
||||
|
||||
![]()
I think that this is proof that IE8 is "not ready yet"...typical of any microsoft product when it is actually released! Have you tried it with IE7/Firefox 3/Safari etc etc? Does it work in these?
Worth a shot: If you want a quick way of trying out IE7, you need to look at Virtual PC 2007 from MS. Its a free download, and will let you run a seperate XP OS at the same time as your host OS. Might be worth getting hold of some extra RAM which you can assign to the Virtual OS, as it will slow your machine down a bit. HTH Mark
__________________
:: AE B5MCE - SP 7.5 v3.0 Brushless Motor - Reedy Shorty Lipo - Savox Servo - Spektrum Rx :: :: Paint By Turnip Paint :: |
#4
|
|||
|
|||
![]()
Cheers for that Mark! Sounds like you've been in my shoes before then? What area do you work in then?
__________________
Previously: BRCA Micro Section Chairman. BRCA Micro National Champion. Currently: JQ fan. Bellend. Forums are better than Facebook groups ![]() |
#5
|
|||
|
|||
![]()
Right, just need one piece of advice if anyone is able to help??
When I run the above code, and enter a VALID password it shows the alert as below, however, if the password is NOT valid the code just seems to get lost and then I have to close IE. Does anyone know how I can get past Code:
if (intValidPassword = 1); alert("Your password is valid!") Thanks ![]() Code:
<script language = "JavaScript"> function validatePassword() { //Declare and initilise variables var intIncludesAt = 0; //Changes to 1 if an @ sign is found var intValidPassword = 0; var intIncludesAt = 0; var strPassword = prompt("Please enter a valid password",""); var intFirstChar = parseInt(strPassword.charAt(0)); //First character of the password while(intValidPassword == 0) { for (intCount = 0; intCount < strPassword.length; intCount ++) { if(strPassword.charAt(intCount) == "@") { intIncludesAt = 1; } } if (strPassword.length >= 6 && intIncludesAt == 1 && intFirstChar == 0) { intValidPassword = 1; } } if (intValidPassword = 1); alert("Your password is valid!") } </script>
__________________
Previously: BRCA Micro Section Chairman. BRCA Micro National Champion. Currently: JQ fan. Bellend. Forums are better than Facebook groups ![]() |
#6
|
||||
|
||||
![]()
Under 'fail' conditions, your while loop is not getting any new information upon which to re-evaluate the situation. Once a fail, always a fail
![]() Regards, Jon. |
#7
|
|||
|
|||
![]()
Jon,
Can you give me a hint as to which line to move? Thanks for the reply ![]() Cris
__________________
Previously: BRCA Micro Section Chairman. BRCA Micro National Champion. Currently: JQ fan. Bellend. Forums are better than Facebook groups ![]() |
#8
|
|||
|
|||
![]()
Also, I presume that
Code:
if (intValidPassword = 1); alert("Your password is valid!") Code:
if (intValidPassword == 1); alert("Your password is valid!") Thanks ![]()
__________________
Previously: BRCA Micro Section Chairman. BRCA Micro National Champion. Currently: JQ fan. Bellend. Forums are better than Facebook groups ![]() |
#9
|
||||
|
||||
![]()
Actually it's 2 lines. I was looking at post 2 when I wrote 1 line.
Moving Quote:
Tweaked a little further it will handle the cancel button too: Quote:
![]() And yes to your last question. Regards, Jon. |
#10
|
|||
|
|||
![]()
*bows at your feet*
Thanks a tonne Jon!
__________________
Previously: BRCA Micro Section Chairman. BRCA Micro National Champion. Currently: JQ fan. Bellend. Forums are better than Facebook groups ![]() |
#11
|
||||
|
||||
![]() |
![]() |
Thread Tools | |
Display Modes | |
|
|