I'm fairly new to javascript and am having a problem validating a password. Here is what I have....

Javascript :

function ValPass() {
	var invalid " ";
	var min = 8;
	var lower = /[a-z]/;
	var upper = /[A-Z]/;
	var numeric = /[0-9]/;
	var pass1 = document.passForm.password.value;
	var pass2 = document.passForm.passcheck.value;

	if(pass1 == '' || pass2 == '')
		alert('All fields must be properly filled in.');
		return false;
	}
	elseif(document.passForm.password.value.indexOf(invalid) > -1) {
		alert('No spaces are allowed.');
		return false;
	}
	elseif(pass1 != pass2) {
		alert('Your passwords do not match');
		return false;
	}
	elseif(document.passForm.password.value.length < min) {
		alert('Your password must be at least ' + min + ' characters long.');
		return false;
	}
	elseif(document.passForm.password.value.search(lower) == -1) {
		alert('Your password must contain at least one lowercase letter.');
		return false;
	}
	elseif(document.passForm.password.value.search(upper) == -1) {
		alert('Your password must contain at least one uppercase letter.');
		return false;
	}
	elseif(document.passForm.password.value.search(numeric) == -1) {
		alert('Your password must contain at least one number');
		return false;
	}

	return true;
}
}

Form :

<form name="passForm" onSubmit="return ValPass();" action="" method="post">
Password 1 : <input type="password" name="password"><br />
Password 2 : <input type="password" name="passcheck"><br />
<input type="submit" name="insert_pass" value="Submit">
</form>

I validate the password with PHP after anyway but I'd like to have something client side as well. Any help is appreciated.

there is no elseif in javascript. You need a space between the else and the if!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.