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 thanksSid
20040318 Edit by Corion: Added code tags
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Allow empty form fields regex
by matija (Priest) on Mar 18, 2004 at 16:12 UTC | |
by Hissingsid (Sexton) on Mar 18, 2004 at 16:55 UTC | |
by Hissingsid (Sexton) on Mar 18, 2004 at 17:18 UTC | |
Re: Allow empty form fields regex
by Paladin (Vicar) on Mar 18, 2004 at 16:08 UTC | |
Re: Allow empty form fields regex
by tcf22 (Priest) on Mar 18, 2004 at 16:07 UTC |
Back to
Seekers of Perl Wisdom