Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Senior Coder durangod's Avatar
    Join Date
    Nov 2010
    southwestern USA
    Thanked 34 Times in 33 Posts

    checking for duplicate input

    on a password field i would like to prevent them from entering 00000 or xxxxx any char more than twice consecutively, i know there are names that are spelled with double o's so im thinking that twice is enough anything more than that would not be allowed.

    i would like it to be set to check for more than twice consecutive and also more than 4x whole string..

    i have all spaces coverd i just remove them, so im ok there but not sure how i would go about checking for the rest..

    i know how to do value.indexof but i would have to give it an array to check correct? just not sure what function to use here..

    maybe im going about this the wrong way here. the bottom line is i dont want anyone to be able to type in xxxxxx or 000000 or ...... or anything like that as a password..

    update : maybe i can use count_chars function
    Last edited by durangod; 12-08-2010 at 03:01 PM.

  • #2
    New Coder
    Join Date
    Oct 2010
    Thanked 2 Times in 2 Posts
    I think you want to use a regular expression.

    PHP Code:
    if(preg_match('/(.)(?=\1{2})/i',$string)) die('You entered three or more of the same characters in a row!'); 
    preg_match() uses a regular expression to search a string.

    the (.) in the first part says store a character in the reference \1
    the (?=\1{2}) tells it to look for two more of the same immediately following it
    $string (the second parameter) would be your input

    You might want to google regular expressions for more.

    i would like it to be set to check for more than twice consecutive and also more than 4x whole string..
    Not sure what you mean by that, but if you need more help let me know.
    Last edited by jmace; 12-09-2010 at 12:04 AM.

  • Users who have thanked jmace for this post:

    durangod (12-09-2010)


    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts