User Registration Password field - limiting allowed characters?

Discussion in 'PHP' started by btvbill, May 21, 2008.

  1. #1
    I've got my user registration script up & running but what was wondering how I could restrict the user password creation field to something like "please enter 5 to 8 characters, 3 of which must be numbers and the rest alphabetical" with no other characters such as $, @, etc.
    Any help would be appreciated.
     
    btvbill, May 21, 2008 IP
  2. xde5igner.com

    xde5igner.com Well-Known Member

    Messages:
    82
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    113
    Digital Goods:
    1
    #2
    You can use javascript for this purpose.
     
    xde5igner.com, May 21, 2008 IP
  3. xrvel

    xrvel Notable Member

    Messages:
    918
    Likes Received:
    30
    Best Answers:
    2
    Trophy Points:
    225
    #3
    
    
    $pass = $_POST['pass'];
    
    $err = '';
    $min = 5;
    $max = 8;
    
    if (strlen($pass) < $min) {
       $err = 'too short';
    } else if (strlen($pass) > $max) {
       $err = 'too long';
    } else if (!preg_match('/^([a-z0-9]+)+$/i', $pass)) {
       $err = 'invalid char';
    }
    
    
    PHP:
     
    xrvel, May 22, 2008 IP