|
Try Catch issue
I have a function that is called and the error messages form the catch work ok, but the reurn fails as there is a java error at the end of the try statement. I know it will be something ovious, but I can not see it. If no error is caught, then there is no error in the try block.
Any help would be appreciated. Thx
<!---// JavaScript Document--->
<!--- This JavaScript Document is used for ensuring Password Standard --->
<!--- The functions are: --->
<!--- checkPassword() - will validate any password string --->
//
<!--- <INPUT type="password" name="userpassword" maxlength="20" onblur="javascript: return checkPassword(this);"> --->
//
<!--- You can set the maxlength to a shorter length if necessary for your application --->
<!--- ---------------------------------------------------- --->
<!--- Global Variables --->
<!--- ---------------------------------------------------- --->
var n;
var passwordValue;
var passwordObject;
<!--- ------------------------------------------------------------- --->
<!--- Function checkPassword() - will validate password string --->
<!--- ------------------------------------------------------------- --->
function checkPassword(formField)
{
var ValidNumericChars = "0123456789";
var hasNoNumeric = true;
var ValidUpperAlphaNumericChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var hasNoUpperAlphaNumeric = true;
var ValidSpecialChars = "!@#$%^*()?<>[]{}\|`~_-=+?/";
var hasNoSpecial = true;
n=formField.name;
passwordObject=formField;
passwordValue=passwordObject.value;
for(i = 0; i < ValidNumericChars.length; i++)
{
cCharacter = ValidNumericChars.charAt(i);
if(passwordValue.indexOf(cCharacter) != -1)
{hasNoNumeric = false;}
}
for(i = 0; i < ValidUpperAlphaNumericChars.length; i++)
{
Char = ValidUpperAlphaNumericChars.charAt(i);
if(passwordValue.indexOf(Char) >= 0)
{hasNoUpperAlphaNumeric = false;}
}
for(i = 0; i < ValidSpecialChars.length; i++)
{
Char = ValidSpecialChars.charAt(i);
if(passwordValue.indexOf(Char) >= 0)
{hasNoSpecial = false;}
}
try
{
if(passwordValue.length < 8){throw "SHORT";}
if(passwordValue.length > 20){throw "LONG";}
if(hasNoNumeric){throw "NONUMERIC";}
if(hasNoUpperAlphaNumeric){throw "NOUPPERALPHANUMERIC";}
if(hasNoSpecial){throw "NOSPECIAL";}
}
catch(error)
{
if(error == "SHORT"){alert("Password must be at least 8 characters in length");}
if(error == "LONG"){alert("Password must be no more than 20 characters in length");}
if(error == "NONUMERIC"){alert("Password must contain at least one number\n"+ValidNumericChars);}
if(error == "NOUPPERALPHANUMERIC"){alert("Password must contain at least one upper case character\n"+ValidUpperAlphaNumericChars);}
if(error == "NOSPECIAL"){alert("Password must contain at least one special character\n"+ValidSpecialChars);}
setCursorPosition(passwordObject, passwordValue.length, passwordValue.length);
return false;
}
}
<!---// End--->
|