Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

password validation question

Status
Not open for further replies.

awingnut

Programmer
Feb 24, 2003
759
US
I have cloned some password validation code (using RegExp) and adapted it to my own needs. However, none test for repeated characters. Can someone come up with a simple way to test a string for more then 2 characters that are the same? All I can come up with is a test in a loop for each letter, number and special character. There has to be a clever and easier way. TIA.
 
i dont think thats possible in RegEx also. it will be easier in the loop way...

Known is handfull, Unknown is worldfull
 
Hi,

Does anybody knows how to check is a string contains any numbers or special characters using Reg expresions.

Thanks
 
awingnut,

This can be tailored to fit your specs, right now it
checks for a char enter consec. is that what you are looking
for? Let us know.

Code:
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>
<html><head><title>TEST</title>
<script>
function ckdbl(str){
 for(i=0;i<str.length;i++) {
  re = new RegExp(str.charAt(i)+str.charAt(i),&quot;i&quot;);
  rslt = str.match(re);
  alert(rslt);
  if(rslt && rslt.length > 0){
   alert(&quot;More than 2 in a row&quot;); break;}}
}
</script></head><body>
<input type=&quot;text&quot; size=&quot;25&quot; name=&quot;test&quot; onChange=&quot;ckdbl(this.value);&quot;>
</body></html>

2b||!2b
 
tbh, if you enforce draconian passwording 'rules' you might actually be lessening security (by basically forcing folks to write the password down next to their pc).

Have a read of:
and
If you really need to, it should be possible to check for doubled chars in a string. It's probably O(n^2)/2 ..
As in:
-loop through string char by char
-loop through rest of string from this char
- if you find another char the same, break & return error
-next
-next

Posting code? Wrap it with code tags: [ignore]
Code:
[/ignore][code]CodeHere
[ignore][/code][/ignore].
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top