How to test a string for invalid chars ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Pjotr Wedersteers

    How to test a string for invalid chars ?

    I think I am having a big blind-spot day. How does one test a form-sent
    string for any disallowed characters again ? I want only a.z,A..Z,0..9,- and
    _ in the input... Thanks.
    Pjotr

    --
    The day Microsoft starts making stuff that does not suck will undoubtedly be
    the day they start producing vacuum cleaners


  • Thomas Mlynarczyk

    #2
    Re: How to test a string for invalid chars ?

    Also sprach Pjotr Wedersteers:
    [color=blue]
    > I think I am having a big blind-spot day. How does one test a
    > form-sent string for any disallowed characters again ? I want only
    > a.z,A..Z,0..9,- and _ in the input... Thanks.[/color]

    if(!preg_match( '/^[a-zA-Z0-9_-]*$/', $input)) {
    echo 'Invalid input!';
    }
    else {
    echo 'Well done!';
    }



    Comment

    Working...