Small adjustment

Discussion in 'Programming' started by oo7ml, Jun 27, 2007.

  1. #1
    I want to create some PHP validation for my Name input box on my form

    For my Username input box, i have
    if (preg_match('/^[a-z0-9_]{5,20}$/i', $username))
    PHP:
    This checks that the username is 5 - 20 characters in length and that a-z 0-9 _ characters are only used

    How do i create a validation similar to above that only checks that the name input box is 1-20 characters in length (any characters can be used)

    Thanks
     
    oo7ml, Jun 27, 2007 IP
  2. sm9ai

    sm9ai Active Member

    Messages:
    746
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    60
    #2
    Hmm, short of adding all the characters aI'm not too sure.

    You could always use strlen instread

    if ((strlen($username)>=1) AND (strlen($username)<=20))
    {
    Validate
    }
    else
    {
    error
    }

    etc.
     
    sm9ai, Jun 27, 2007 IP
  3. gibex

    gibex Active Member

    Messages:
    1,060
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    95
    #3
    or :

    if (preg_match('/^.{1,20}$/i', $username))
    PHP:
     
    gibex, Jun 27, 2007 IP