0

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.

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by hielo
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.