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 }
LVL 2
brgdotnetcontractorAsked:
Who is Participating?
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.
0

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 }
0
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.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

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?
0
Dave BaldwinFixer of ProblemsCommented:
As far as I know it is.  I have seen it done.
0
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.
0
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
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.