Thread: Will this work?

    #1
  1. No Profile Picture
    Banned
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Apr 2005
    Posts
    4,982
    Rep Power
    0

    Will this work?


    Will this => ^[A-Za-z0-9 -]*$ work to match and number and combnation of letters, numbers, spaces, and a dash?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    London, England
    Posts
    1,585
    Rep Power
    1373
    Nearly - you need to put the "-" as the first character in the square brackets, otherwise it will complain that you have an unterminated range starting from space. i.e.
    ^[-A-Za-z0-9 ]*$

    It will also match an empty string, which may or may not be what you want. If you want it to match at least one character then replace the * with +.

    Dave
  4. #3
  5. No Profile Picture
    User 165270
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2005
    Posts
    497
    Rep Power
    937
    Originally Posted by DevCoach
    Nearly - you need to put the "-" as the first character in the square brackets, otherwise it will complain that you have an unterminated range starting from space. ...
    No, the hyphen is not "seen" as a range character when placed at the start and end of a character class.

    Comments on this post

    • Kravvitz agrees

IMN logo majestic logo threadwatch logo seochat tools logo