0

Hi everyone, i am trying to validate password entered into my system from a jsp page, i want to create a method that would check that a password entered is not less than six characters and not more than 15. Does anyone have an idea on how i could go about this. Cheers.:sad:

6
Contributors
6
Replies
8
Views
10 Years
Discussion Span
Last Post by stultuske
0
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="javascript">
function validatePwd()
{
	var pw1 = document.getElementById("Npass").value;
	var pw2 = document.getElementById("Cpass").value;
	// check for a value in both fields.
if (pw1 ==NULL  || pw2 == NULL) 
	{
	alert('Please enter your password .');
	return false;
	}

if (pw1 != pw2)
	{
		alert ("You did not enter the same new password twice. Please re-enter your password.");
		return false;
	}
else 
		{
			alert('Nice job.');
			return true;
      	}
}
</script>
</head>
<body>
<form name="form1" method="post" action="" >

<p>New Password: 
  <input name="Npass" type="text" id="Npass">
</p>
<p>Confirm Password: 
  <input name="Cpass" type="text" id="Npass">
</p>
<p>
  <input type="submit" name="Submit" value="Submit" onClick="return validatePwd()">
</p>
</form>
</body>
</html>
0

@ Nikhil: Wouldn't it be better to check the date before posting. the question was asked almost 5 years ago.

0

and to check the technology?
considering the fact that this is a 'Java' forum, giving a solution in javascript might not be what the OP was looking for.

now ... next to mine and verruckt24's remark, there was another issue with his post, anyone found that one yet? :)
(Yeah, I'm bored ..)

-1
<html>
<head>
<title>Pwd validation using js</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="javascript">
function validatePwd()

{


var pw1 = document.getElementById("Npass").value;
var pw2 = document.getElementById("Cpass").value;

if (pw1 ==null || pw2 ==null || pw1 == '' || pw2 =='' )
{  alert('The Pwd field is balank or user not confirmed the pwd');
    document.form1.Npass.value=''
    document.form1.Cpass.value=''
return false;	}

if (pw1!= pw2)	{
alert ("You did not enter the same new password twice. Please re-enter your password.");
document.form1.Npass.value=''
document.form1.Cpass.value=''


return false;
}else
{alert('Nice job.');
return true;
}
}
</script>
</head>
<body><form name="form1" method="post" action="" >
<p>New Password:   <input name="Npass" type="password" id="Npass"></p>
<p>Confirm Password:<input name="Cpass" type="password" id="Cpass">
</p><p>  <input type="submit" name="Submit" value="Submit" onClick="return validatePwd()">
</p>
</form>
</body>
</html>

Edited by peter_budo: Keep It Clear - Do wrap your programming code blocks within [code] ... [/code] tags

Votes + Comments
Pleae learn difference between Java and JavaScript, also please read previous replies before dropping your code without any comment
0

Abdul ...
in the two posts previous to your own, we've given two reasons why NOT to revive or answer to this thread.
not obvious enough?

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.