javascript not working - password strength

Im trying to check a strength of a password but it does not seem to do anything on the page

      <input type="text" name="username" id="username" />
       <div class="username_avail_result" id="username_avail_result"></div>
     <input type="text" name="password" id="password" />
     <div class="password_strength" id="password_strength"></div>

	$('#username').keyup(function(){ // Keyup function for check the user action in input
		var Username = $(this).val(); // Get the username textbox using $(this) or you can use directly $('#username')
		var UsernameAvailResult = $('#username_avail_result'); // Get the ID of the result where we gonna display the results
		if(Username.length > 2) { // check if greater than 2 (minimum 3)
			UsernameAvailResult.html('Loading..'); // Preloader, use can use loading animation here
			var UrlToPass = 'action=username_availability&username='+Username;
			$.ajax({ // Send the username val to another checker.php using Ajax in POST menthod
			type : 'POST',
			data : UrlToPass,
			url  : 'Username_Checker/checker.php',
			success: function(responseText){ // Get the result and asign to each cases
				if(responseText == 0){
					UsernameAvailResult.html('<span class="success">Username name available</span>');
				else if(responseText > 0){
					UsernameAvailResult.html('<span class="error">Username already taken</span>');
					alert('Problem with sql query');
			UsernameAvailResult.html('Enter atleast 3 characters');
		if(Username.length == 0) {
	$('#password, #username').keydown(function(e) { // Dont allow users to enter spaces for their username and passwords
		if (e.which == 32) {
			return false;
		checkStrength is function which will do the 
		main password strength checking for us
	function checkStrength(password)
		//initial strength
		var strength = 0
		//if the password length is less than 6, return message.
		if (password.length < 6) { 
			return 'Too short' 
		//length is ok, lets continue.
		//if length is 8 characters or more, increase strength value
		if (password.length > 7) strength += 1
		//if password contains both lower and uppercase characters, increase strength value
		if (password.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/))  strength += 1
		//if it has numbers and characters, increase strength value
		if (password.match(/([a-zA-Z])/) && password.match(/([0-9])/))  strength += 1 
		//if it has one special character, increase strength value
		if (password.match(/([!,%,&,@,#,$,^,*,?,_,~])/))  strength += 1
		//if it has two special characters, increase strength value
		if (password.match(/(.*[!,%,&,@,#,$,^,*,?,_,~].*[!,%,&,@,#,$,^,*,?,_,~])/)) strength += 1
		//now we have calculated strength value, we can return messages
		//if value is less than 2
		if (strength < 2 )
			return 'Weak'			
		else if (strength == 2 )
			return 'Good'		
			return 'Strong'

Open in new window

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.

Ray PaseurCommented:
Have you tried looking at this with Chrome Dev Tools?  It usually will tell you exactly what statement is wrong.

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
runnerjp2005Author Commented:
Missed a ' out on line53.

Thanks for teaching me how to fish ;)
Ray PaseurCommented:
Thanks for the points.  The Dev Tools are just excellent for dealing with anything in JS and CSS.  I'm amazed we didn't have them all along!

All the best, ~Ray
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.

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.