in reply to Allow empty form fields regex
First, the operator to bind a regex match to a variable is =~ and to negate that, it's !~
Second, the operator to compare strings is eq. = is the assignment operator.
Now that that's out of the way, you could do something like:
This will first check if $contents is not empty, and if it's not, then check it against the regex, and if the regex doesn't match, then execute the body of the if statement.if ( ($contents ne "") && ($contents !~ /^[\w \.\,\=\" \/<>]+$/) ){ $contentserror = "Error - message.";++$error; }
|
|---|