I need help with this regex

Discussion in 'PHP' started by x0x, Feb 20, 2009.

  1. #1
    I don't understand it AT ALL:

    /^[a-z0-9][a-z0-9\.\-_]*$/i

    And I don't need to... I just want to modify it to allow spaces. BUT not only spaces, just like not only _ and - (that should be there already). So Spaces with characters and numbers only. Can it be done?
     
    x0x, Feb 20, 2009 IP
  2. beezzee

    beezzee Peon

    Messages:
    37
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    add \s
    /^[a-z0-9][a-z0-9\.\-_\s]*$/i
     
    beezzee, Feb 20, 2009 IP
  3. x0x

    x0x Well-Known Member

    Messages:
    510
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    110
    #3
    Thank You!
     
    x0x, Feb 20, 2009 IP
  4. x0x

    x0x Well-Known Member

    Messages:
    510
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    110
    #4
    How could I make it allow only ONE space? And two? Both versions please, if possible.
     
    x0x, Feb 20, 2009 IP
  5. dowhile

    dowhile Active Member

    Messages:
    37
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    93
    #5
    Try this:
    for one space:
    /^[a-z0-9](\s?[a-z0-9\.\-_]*|[a-z0-9\.\-_]*\s|[a-z0-9\.\-_]*\s[a-z0-9\.\-_]*)$/i
    for two spaces
    /^[a-z0-9]((\s\s)?[a-z0-9\.\-_]*|[a-z0-9\.\-_]*\s\s|[a-z0-9\.\-_]*\s\s[a-z0-9\.\-_]*)$/i
     
    dowhile, Feb 20, 2009 IP
  6. x0x

    x0x Well-Known Member

    Messages:
    510
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    110
    #6
    It works. Thank you!!
     
    x0x, Feb 20, 2009 IP