How to check if string is a-Z 0-9 and -

Discussion in 'PHP' started by Psychotomus1, Oct 2, 2007.

  1. #1
    how can I check if a string is a-Z 0-9 and the - symbol.
     
    Psychotomus1, Oct 2, 2007 IP
  2. kendo1979

    kendo1979 Peon

    Messages:
    208
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    use preg_match

    preg_match ( string pattern, string subject [, array &matches [, int flags [, int offset]]] )
     
    kendo1979, Oct 2, 2007 IP
  3. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #3
    The pattern you need is /^[a-z0-9-]+$/i or you can do the opposite:
    if (!preg_match("/[^a-z0-9-]/", ...
     
    krt, Oct 2, 2007 IP
  4. Psychotomus1

    Psychotomus1 Banned

    Messages:
    411
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    thanks krt.
     
    Psychotomus1, Oct 2, 2007 IP