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!

Validate 2 Passwords

Status
Not open for further replies.

pandapark

Technical User
Jan 29, 2003
92
0
0
GB
I've got a form, called Key, which on submit calls this function (there is Validation.js file which is called)

function validate(formToValidate)
{
var ErrorMsg = "";
ErrorMsg += validateMandatoryText(formToValidate.elements("Org_Name"));
ErrorMsg += validateMandatoryPostCode(formToValidate.elements("PostCode_1"));
ErrorMsg += validateMandatoryText(formToValidate.elements("Address1_1"));
ErrorMsg += validateOptionalText(formToValidate.elements("Address2_1"));
ErrorMsg += validateOptionalText(formToValidate.elements("Address3_1"));
ErrorMsg += validateOptionalText(formToValidate.elements("Address4_1"));
ErrorMsg += validateOptionalText(formToValidate.elements("Address5_1"));
ErrorMsg += validateOptionalText(formToValidate.elements("Town_1"));
ErrorMsg += validateOptionalText(formToValidate.elements("County_1"));
ErrorMsg += validateMandatoryEmail(formToValidate.elements("Email"));
ErrorMsg += combocheck1(formToValidate.elements("Org_Type"));

if(ErrorMsg!="")
{
ErrorMsg = "The following errors occurred with your submission\n\n" + ErrorMsg;
alert(ErrorMsg);
return false;
}
return true;
}

This is the Validation.js file which has all the functions within. I can't get the ValidatePassword one to work when called in the Key form. Any ideas

function validatePassword(field1, field2)
{
var field1Name;
var field1Value;
var field2Name;
var field2Value;
var paramIsString = false;

if ((typeof(field1) == "string") && (typeof(field2) == "string"))
{
paramIsString = true;
field1Name = "Password 1";
field1Value = field1;
field2Name = "Password 2";
field2Value = field2;
}
else
{
field1Name = field1.name;
field1Value = field1.value;
field2Name = field2.name;
field2Value = field2.value;
}

var correct = true;

if (!(field1Value==field2Value))
{
alert("Passwords must match");
correct = false;
}
else
{

if (field1Value.length < 6)
{
alert(&quot;Password must be 6 or more characters long&quot;);
correct = false;
}
else if (disAllowInString(field1Value, &quot;0123456789&quot;))
{
alert(&quot;The password must contain letters and numbers&quot;);
correct = false;
}
else if (disAllowInString(field1Value, &quot;abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ&quot;))
{
alert(&quot;The password must contain letters and numbers&quot;);
correct = false;
}
else if (!(disAllowInString(field1Value, &quot;¬`!\&quot;£$%^&*()_+-=€{}[]:mad:~;'#<>?,./|\\&quot;)))
{
alert(&quot;The password must only contain letters and numbers&quot;);
correct = false;
}
}

if (!(correct))
{
if (!(paramIsString))
{
field1.value = &quot;&quot;;
field2.value = &quot;&quot;;
field1.focus();
}
return false;
}
else
{
return true;
}
}
 
what is the error that is raised?

Known is handfull, Unknown is worldfull
 
Hi

There is no error message - the page submits without calling the validation

I tried
ErrorMsg += validatePassword(formToValidate.elements(&quot;Password&quot;,&quot;Password1&quot;);

regards
 
looks like you're returning true no matter what you do
eg:
if(ErrorMsg!=&quot;&quot;)
{
ErrorMsg = &quot;The following errors occurred with your submission\n\n&quot; + ErrorMsg;
alert(ErrorMsg);
return false;
}
return true;
}

maybe a
} else {
return true;
}

and shouldn't you be passing two values to the password validation
as in
ErrorMsg += validatePassword(formToValidate.elements(&quot;Password1&quot;),formToValidate.elements(&quot;Password2&quot;));

____________________________________________________
[sub]The most important part of your thread is the subject line.
Make it clear and about the topic so we can find it later for reference. Please!! faq333-2924[/sub]
onpnt2.gif
 
The return false in the statement also would hault the submission as long as you call the function with a return.
are you calling as
<form onSubmit=&quot;return validate(this)&quot;>

____________________________________________________
[sub]The most important part of your thread is the subject line.
Make it clear and about the topic so we can find it later for reference. Please!! faq333-2924[/sub]
onpnt2.gif
 
Yeah I'm calling return validate(this) on the submit of the form and it works fine except I can't get the Password one to work.
I thought the ValidatePassword function in my js script was ok and my problem lay when calling it as
ErrorMsg += validatePassword(formToValidate.elements(&quot;Password&quot;,&quot;Password1&quot;);
but maybe the ValidatePassword function is wrong???
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top