Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Allow empty form fields regex

by matija (Priest)
on Mar 18, 2004 at 16:12 UTC ( [id://337719]=note: print w/replies, xml ) Need Help??


in reply to Allow empty form fields regex

Well, at first I wanted to say you only need to add a |(^$) to your regexp, but some experimentation has showed me that doesn't work.

Then I took a good look at you regexp. You are accepting any of a class of characters, one or more times. To accept an empty field as well, simply change the + to *:

if ($contents != /^[\w \.\,\=\" \/<>]*$/ ){ $contentserror = "Error - message.";++$error; }
It's not a general answer, but in your particular case, it should work.

Replies are listed 'Best First'.
Re: Re: Allow empty form fields regex
by Hissingsid (Sexton) on Mar 18, 2004 at 16:55 UTC
    Hi,

    Thanks for the excellent input.

    I played around a bit and this is what I have got working perfectly.

    if (($contents ne "") && (!($contents =~ /^[\w \.\,\=\" \/<>]+$/))){ $contentserror = "Error - message.";++$error; }
    For some reason this != was not helping the situation.

    Anyway Paladin, a big thanks I had been fiddleing for hours and now have a good solution thanks to your suggestion.

    Best wishes

    Sid

    Edit by castaway, added code tags

      Apologies guys I missed the bit about !=/!~

      !~ does indeed work removing the need for some of the ()s.

      Many thanks Sid

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://337719]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2024-04-19 21:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found