Acceptable characters are a-zA-Z0-9 and ; in php regex how can I do this?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dagam3rz
    New Member
    • Jul 2010
    • 11

    Acceptable characters are a-zA-Z0-9 and ; in php regex how can I do this?

    Here is the scenario: I'm filtering the data being submitted by the user. Acceptable characters are a-zA-Z0-9 and semicolon(;) in php regex how can I do this?

    Semicolon(;) serve as delimiter, so I'll be splitting the string into an array.

    Please help.

    Tenx!
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #2
    You basically did it. your class is [a-zA-Z0-9;]

    For what you need it is

    Code:
    if(preg_match('/^[a-z0-9;]+$/i',$foo))
    {
       $data = explode(';',$foo); 
      // it matches, do stuff
    }
    Explanation: From beginning of the string (^) to end ($), ensure there are one more of the following characters a-z, and numbers 0-9 in any order, case Insensitive (i).

    Cheers,

    Dan

    Comment

    • dagam3rz
      New Member
      • Jul 2010
      • 11

      #3
      Now its working using your code. The + sign before the $ sign is what I omitted in my code. So I have decided to post it here for an immediate solution.

      Thanks friend, you're the man.

      Comment

      Working...