in reply to String Validation

There is ONE thing I still down understand and thats reguarding !@#$%^&* symbols. The field I'm checking is 'lastname' I want to make sure they cant put any bad things like % in there, but I need to allow ' or " " (space) so that people like O'Mally or Las Luther can still "pass". I havent found one example that shows how to do this.

Replies are listed 'Best First'.
Re^2: String Validation
by ikegami (Patriarch) on Mar 09, 2007 at 20:17 UTC
    if ($lastname =~ /[^a-zA-Z' -]/) { die("Bad character\n"); }
    • [...] matches any one character among those listed or those in the listed character ranges.
    • [^...] matches any one character not among those listed or those in the listed character ranges.

    Ref: perlre