Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Allow empty form fields regex

by Paladin (Vicar)
on Mar 18, 2004 at 16:08 UTC ( [id://337718]=note: print w/replies, xml ) Need Help??


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:

if ( ($contents ne "") && ($contents !~ /^[\w \.\,\=\" \/<>]+$/) ){ $contentserror = "Error - message.";++$error; }
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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-04-16 10:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found