By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,374 Members | 1,782 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,374 IT Pros & Developers. It's quick & easy.

Password validation

P: 15
How to test that the password should satisfy the following condition
1) It should be atleast 6 char long
2) It should contain alphanumeric values with atleast 1 character and number.
3) It should not contain any repeated consecutive characters.

Any help on this is really appreciated. Thanks in advance.
Oct 14 '06 #1
Share this Question
Share on Google+
4 Replies


iam_clint
Expert 100+
P: 1,208
alright i am back to helping people on the scripts too many javascript questions have gone unanswered! :P

anyways give us some of your code that you need validated so i can help you farther but variable.length would get you how many characters are in that variable
Oct 15 '06 #2

P: 15
I just want the regular expression satisfying the first two conditions.
The third one I can manage.
Oct 16 '06 #3

P: 1
Here is some code that will make this happen for you.

var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var checkStr = theForm.Password.value.toUpperCase();
var allValid = false;
for (i = 0; i < checkOK.length; i++)
{
ch = checkOK.charAt(i);
if (checkStr.indexOf(ch) >= 0)
{
allValid = true;
break;
}
}
if (!allValid)
{
alert("Your Password must contain at least 1 letter character (A-Z) - Please Re-Enter");
theForm.Password.focus();
return (false);
}
var checkOK = "0123456789";
var checkStr = theForm.Password.value;
var allValid = false;
for (i = 0; i < checkOK.length; i++)
{
ch = checkOK.charAt(i);
if (checkStr.indexOf(ch) >= 0)
{
allValid = true;
break;
}
}
if (!allValid)
{
alert("Your Password must contain at least 1 Numeric Character (0-9) - Please Re-Enter");
theForm.Password.focus();
return (false);
}
Oct 31 '06 #4

P: 15
Passwords are case sensitive. So 'A' and 'a' are different. So in your code if I enter 'PASSWORD' or 'password' your code will validate both the values. If we can have a regular expression than this validation will be easier..
Anyway thanks for your help!!!
Nov 2 '06 #5

Post your reply

Sign in to post your reply or Sign up for a free account.