Letter filter code.

Discussion in 'PHP' started by TommyD, Oct 18, 2005.

  1. #1
    Now I didn't find anything in the searches; so, posting a new thread.

    I have data fields where users can enter anything. I would like to strip out characters that aren't a number, or a letter(a-z, and A-Z). I think it's a simple solution, if I pass the right parameters to replace_str(), but I have not found it.

    Anyone know a simple solution?

    thanks,

    tom
     
    TommyD, Oct 18, 2005 IP
  2. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,334
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #2
    I think this should work...
    preg_replace ("#[^a-z0-9]#i", '', $field);
    PHP:
     
    digitalpoint, Oct 18, 2005 IP
  3. TommyD

    TommyD Peon

    Messages:
    1,397
    Likes Received:
    76
    Best Answers:
    0
    Trophy Points:
    0
    #3
    WOO HOO!

    Thank you very much Shawn! Worked like a charm. Funny how once you are shown the solution, how easy it looks. :)

    Thanks,

    tom
     
    TommyD, Oct 18, 2005 IP