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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Testing length of password?

Status
Not open for further replies.

wuzzle

Programmer
Dec 20, 2000
75
CA
Shouldn't this test to see how long their password is? It doens't do anything! Even if I take out the first emptyValidation part.

function formValidation(PasswordForm)
{
with (PasswordForm)
{
if (emptyValidation(txtPassword, "Please enter a password.") == false)
{
txtPassword.focus();
return false;
}
if (txtPassword.length < 6)
{
alert('Your password must be at least 6 characters long.')
}
if (emptyValidation(ConfirmPassword, &quot;Please enter a confirmation password.&quot;) == false)
{
ConfirmPassword.focus();
return false;
}
}
}
 
well, I dont really understand your code, especially with
Code:
emptyValidation()
in there, but try this:

add this line right after the { of you function declaration:

txtPassword=document.formName.txtPassword;

where formName is the name of the form where the password box lies. Robert Carpenter
questions? comments? thanks? email me!
linkemapx@hotmail.com
Icq: 124408594
online.dll

AIM & MSN: robacarp
 
The emptyValidation is there because I have a function which checks to see if fields are empty (I didn't post ALL of my code on here, I could if that would help).

I changed it to this and it doesn't make a difference.

function formValidation(PasswordForm)
{
txtPassword=document.PasswordForm.txtPassword;

with (PasswordForm)
{
if (emptyValidation(txtPassword, &quot;Please enter a password.&quot;) == false)
{
txtPassword.focus();
return false;
}
if (txtPassword.length < 6)
{
alert('Your password must be at least 6 characters long.')
}
if (emptyValidation(ConfirmPassword, &quot;Please enter a confirmation password.&quot;) == false)
{
ConfirmPassword.focus();
return false;
}
}
}

 
you might try that. I think the problem could actually be in your emptyValidation code
Robert Carpenter
questions? comments? thanks? email me!
linkemapx@hotmail.com
Icq: 124408594
online.dll

AIM & MSN: robacarp
 
Oh no! Here's the code for that.

function emptyValidation(entered, alertbox)
{
with (entered)
{
if (value == null || value == &quot;&quot;)
{
if (alertbox!=&quot;&quot;)
{
alert(alertbox);
}
return false;
}
else
{
return true;
}
}
}
 
ok, well, I dont know what your problem is, it works fine for me. here is the whole html page i used.

Code:
<html>
<head>
<title></title>
<script language=javascript>
function emptyValidation(entered, alertbox)
{
    with (entered)
    {
        if (value == null || value == &quot;&quot;)
        {
            if (alertbox!=&quot;&quot;) 
            {
                alert(alertbox);
            } 
            return false;
        }
        else 
        {
            return true;
        }
    }    
}

function formValidation(PasswordForm)
{
    //txtPassword=document.PasswordForm.txtPassword;
    
    with (PasswordForm)
    {
        if (emptyValidation(txtPassword, &quot;Please enter a password.&quot;) == false) 
        {
            txtPassword.focus(); 
            return false;
        }
        if (txtPassword.length < 6)
        {
            alert('Your password must be at least 6 characters long.')
        }
        if (emptyValidation(ConfirmPassword, &quot;Please enter a confirmation password.&quot;) == false) 
        {
            ConfirmPassword.focus(); 
            return false;
        }                
    }
}
</script>
</head>
<body>

<form name=&quot;PasswordForm&quot;>
<input type=password name=txtPassword><input type=password name=ConfirmPassword><input type=button onClick=formValidation(this.form)>
</form>

</body>
</html>
Robert Carpenter
questions? comments? thanks? email me!
linkemapx@hotmail.com
Icq: 124408594
online.dll

AIM & MSN: robacarp
 
actually, I just had a thought, its probably in your function call

make sure that it passes a form as a value, not an input.

see above Robert Carpenter
questions? comments? thanks? email me!
linkemapx@hotmail.com
Icq: 124408594
online.dll

AIM & MSN: robacarp
 
Ok...It's still not bringing up the prompt. I'm sorry, I am clueless, and don't even enjoy doing this stuff, so I'm sure I am annoying you like crazy.

Here is all of my javascript:



<SCRIPT language=&quot;JavaScript&quot;>

function NewCompany()
{
var NewCompany= prompt('New Company name:', ' ');

if ( (NewCompany==' ') || (NewCompany==null) )
{
NewCompany=&quot;Null&quot;;
}
}

function NewPlan()
{
var NewPlan= prompt('New Plan name:', ' ');

if ( (NewPlan==' ') || (NewPlan==null) )
{
NewPlan=&quot;Null&quot;;
}
}

function AskDelete()
{
var AskDelete= confirm('Are you sure you want to delete this company?', ' ');
}

function emptyValidation(entered, alertbox)
{
with (entered)
{
if (value == null || value == &quot;&quot;)
{
if (alertbox!=&quot;&quot;)
{
alert(alertbox);
}
return false;
}
else
{
return true;
}
}
}


function formValidation(CompanyName)
{
with (CompanyName)
{
if (emptyValidation(CompanyName, &quot;Please enter a Company Name.&quot;) == false)
{
CompanyName.focus();
return false;
}
}
}

function formValidation(PasswordForm)
{
//txtPassword=document.PasswordForm.txtPassword;

with (PasswordForm)
{
if (emptyValidation(txtPassword, &quot;Please enter a password.&quot;) == false)
{
txtPassword.focus();
return false;
}
if (txtPassword.length < 6)
{
alert('Your password must be at least 6 characters long.')
}
if (emptyValidation(ConfirmPassword, &quot;Please enter a confirmation password.&quot;) == false)
{
ConfirmPassword.focus();
return false;
}
}
}

</SCRIPT>

and here is the form code:



<form id=form1 name=PasswordForm onSubmit=&quot;return(formValidation(PasswordForm))&quot;>
<tr>
<td>
<font face=arial,tahoma size=2 color=#000000>
Password:&nbsp;
</td>
<td>
<input type=password size=12 maxlength=255 name=txtPassword>
</td>
</tr>
<tr>
<td>
<font face=arial,tahoma size=2 color=#000000>
Confirm Password:&nbsp;
</td>
<td>
<input type=password size=12 maxlength=255 name=ConfirmPassword>
</td>
</tr>
<tr>
<td colspan=2 align=right>
<input type=button value=&quot;Apply Change&quot; onClick=formValidation(this.form)>
</td>
</tr>
</form>
 
what browser are you using? Robert Carpenter
questions? comments? thanks? email me!
linkemapx@hotmail.com
Icq: 124408594
online.dll

AIM & MSN: robacarp
 
ok, I dont know what the problem is. do you have javascript disabled or caching enabled? Robert Carpenter
questions? comments? thanks? email me!
linkemapx@hotmail.com
Icq: 124408594
online.dll

AIM & MSN: robacarp
 
Nope!

I don't see why it won't work. You know - even if I take out all of the password stuff and just make it

function formValidation(PasswordForm)
{
//txtPassword=document.PasswordForm.txtPassword;

with (PasswordForm)
{
if (txtPassword.length < 6)
{
alert('Your password must be at least 6 characters long.')
}
}
}

...it still doesn't detect that there are less than 6 characters. Very, very strange...
 
function formValidation(CompanyName){}
function formValidation(PasswordForm){}

CompanyName fuction gets overwritten by PasswordForm function. Try different names.



I think I may have your solution:

Change if (txtPassword.length < 6) in your formValidation function to if (txtPassword.value.length < 6)

&quot;The surest sign that intelligent life exists elsewhere in the universe is that it has never tried to contact us&quot;
Bill Watterson, Calvin & Hobbes
 
Oddly enough, I think it was checking the txtPassword object, which for some reason was undefined, as opposed to it's length. &quot;The surest sign that intelligent life exists elsewhere in the universe is that it has never tried to contact us&quot;
Bill Watterson, Calvin & Hobbes
 
that does explain his problems, but not why it worked on my machine Robert Carpenter
questions? comments? thanks? email me!
linkemapx@hotmail.com
Icq: 124408594
online.dll

AIM & MSN: robacarp
 
I'm still having the problem that I posted in the other thread, but this one is fixed. I'll deal with the other after lunch ;)
 
It would work on my system, just not check the value correctly. Without the .value added in, it was returning &quot;undefined&quot;, so it wasn't triggering the if statement. &quot;The surest sign that intelligent life exists elsewhere in the universe is that it has never tried to contact us&quot;
Bill Watterson, Calvin & Hobbes
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top