http://qs321.pair.com?node_id=337704

Hissingsid has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
I'm using a regex to allow input of some HTML markup into a form field but the field is still acceptable if it is empty. Here is what I'm using which seems to be validating in the way I want it to except if the field is empty then I get a false.

if ($contents != /^[\w \.\,\=\" \/<>]+$/ ){ $contentserror = "Error - message.";++$error; }

My question is: Can you please give me an example of how I can allow the field to be empty but only validate against the regex above if it has any characters in it.

I guess I could hack it by saying this first

if ($contents = ""){ $contents = "\s"; }

and then put it through the regex but that is a real mess.

Any ideas, I've done a few searches but can't find anything to help me out there.

Many thanks
Sid

20040318 Edit by Corion: Added code tags