0

Requirement : To validate password and emailID entered by user. I have designed a dialog for user to enter there email id and password for creating their new account.

I want the the user input to be validated on the "next" button of the dialog. I have written a JavaScript for it as shown below and added a custom action in "do action" of my dialog button.

function validatePassword(str szPasswordportal) 
{
 var newPassword = szPasswordportal;
 var minNumberofChars = 6;
 var maxNumberofChars = 20;
 var regularExpression  = /^[A-Za-z0-9`~!@%]{6,20}$/;
 alert(newPassword);
 if(newPassword = "")   //if null
 return false;
 if(newPassword.length < minNumberofChars || newPassword.length > maxNumberofChars)
 {
     return false;
 }
 if(!regularExpression.password(newPassword))
 {
     alert("password should contain atleast one number ,one alphabet and one special character");
     return false;
 }
    return true;
}

But this JS is not getting executed successfully.

Can someone help me out with this or with some other suggestion?

Hkachhia
  • 4,463
  • 6
  • 41
  • 76

1 Answers1

0

Your if condition have a syntax mistake.

if(newPassword = "")

= is assigning operator. If you want to check the value you have to use conditional operator == like below.

if(newPassword == "")

Also you have to add all the condition on else part, then only it will check the validation one by one, otherwise at the end it will automatically return the true value. Change your script like below.

function validatePassword(str szPasswordportal) 
{
   var newPassword = szPasswordportal;
   var minNumberofChars = 6;
   var maxNumberofChars = 20;
   var regularExpression  = /^[A-Za-z0-9`~!@%]{6,20}$/;
   alert(newPassword);
   if(newPassword == "" || newPassword.length < minNumberofChars || newPassword.length > maxNumberofChars)
   {
      return false;
   } else if(!regularExpression.password(newPassword))
   {
      alert("password should contain atleast one number ,one alphabet and one special character");
      return false;
   } else {
      return true;
   }
}
Suresh Ponnukalai
  • 13,820
  • 5
  • 34
  • 54
  • I have already tried this and facing the same issue. I am looking for installshield JavaScript code. – Hkachhia Jan 09 '18 at 13:22