Equality of variables in Java script

I wrote some Java script code to validate a password. At line 3 an alert box will show me the result of the regular expression validation.
When the result of the test at line 2 is true then the code in lines 4 through 7 should be executed. However it never is?
What am I doing wrong in my syntax at line 4 where I check for equality?? I have tried using just two equal signs == and that is not working either at line 4.

1  var reg = new RegExp(“((?=.{20,})(?=.*[a-z])(?=.*[A-Z])(?=.*[\d]))”);
2   var result = reg.test(password.val() )
3    alert(result);
4  If (result == true)
5 {
6   alert(“Passed”);
7 }
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
First, what are you seeing in the 'alert'?  And 'val()' appears to be a jQuery lbrary function but not a plain JavaScript function.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
brgdotnetcontractorAuthor Commented:
Hi Dave. I will see 'true' being displayed in the first alert box. However if I try and compare it to the word true, it does not equate. But sir you bring up a good question. Actually I am performing this in a JQuery function. Isn't that okay though? Because basically JQuery is just java script.

If did notice that this works:

 var result = reg.test(password.val() )

 4  If (reg.test(password.val() ) // This works. I just am wondering why I can not compare it to word tru
 5 {
 6   alert(“Passed”);
 7 }
Dave BaldwinFixer of ProblemsCommented:
Because 'true' is a reserved word in JavaScript that represents the value of true and you did not quote it as a string.  It might work if you just use "If (result)".

The 'if' statement recognizes the boolean true value returned from the function.
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

brgdotnetcontractorAuthor Commented:
Ok, Mr. Dave. Please do not be stingy with me. You opened an interesting door about using JQuery. Can you answer my other question sir : Is it okay to mix Java script with JQuery?
Dave BaldwinFixer of ProblemsCommented:
As far as I know it is.  I have seen it done.
Julian HansenCommented:
Is it okay to mix Java script with JQuery?
jQuery is JavaScript - it is not possible to use jQuery without JavaScript.

jQuery is written in javascript and is a library for manipulating the DOM. Think of jQuery as a bunch of JavaScript functions that you call - to extend functionality beyond what jQuery provides you have to write more JavaScript.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.