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:

String pass = "crap";

If ( pass.length() > 6 && pass.length() < 15 )
{
}

<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>

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

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 ..)

<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>
commented: Pleae learn difference between Java and JavaScript, also please read previous replies before dropping your code without any comment -3

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?

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.