Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Simple Data Cleaning and Verification

by Notromda (Pilgrim)
on Nov 07, 2002 at 22:37 UTC ( [id://211276]=perlquestion: print w/replies, xml ) Need Help??

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

I've been using perl for a while, and hanging around the monastery for a while, but I can't seem to find (or ask the right question to the search engines) a set of simple routines to check data for validity, such as what one would read in from a web page.

I'm sure there are a lot of regex's that could do the job, and I've written a few myself, but is there any collection somewhere?

For example, it might be nice to do:

print "good" if isEmail($email); print "good" if isCurrency($price); print "good" if isDate($date); print "good" if isPhoneNumber($phone); print "good" if isPrintable($input);
and so on. Some functions are easy, some are more involved. Would this pass taint checking? Is there something like this already out there?

Replies are listed 'Best First'.
Re: Simple Data Cleaning and Verification
by DamnDirtyApe (Curate) on Nov 07, 2002 at 22:49 UTC

    Take a look at Regexp::Common; it has some similar functionality. As far as dates go, take a look at the documentation for Date::Manip; it shows you an easy way to validate a date.


    _______________
    DamnDirtyApe
    Those who know that they are profound strive for clarity. Those who
    would like to seem profound to the crowd strive for obscurity.
                --Friedrich Nietzsche
Re: Simple Data Cleaning and Verification
by Zaxo (Archbishop) on Nov 07, 2002 at 23:16 UTC

    The basic way of clearing a variable's taint flag is to apply the m// operator to the variable. The regex you use for the match determines the quality of your untainting.

    To wrap the match in a sub, you should use the aliased arguments rather than a copy, so that the taint flag is cleared for the external variable. For example, using the unicode printable test:

    sub isPrintable { $_[0] =~ m/^\p(IsPrint)+$/; }

    The Regexp::Common module may be useful to you as a library. Email addresses are notoriously difficult.

    After Compline,
    Zaxo

Re: Simple Data Cleaning and Verification
by waswas-fng (Curate) on Nov 07, 2002 at 22:51 UTC
Re: Simple Data Cleaning and Verification
by perrin (Chancellor) on Nov 07, 2002 at 22:50 UTC
Re: Simple Data Cleaning and Verification
by adrianh (Chancellor) on Nov 08, 2002 at 11:48 UTC

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-24 01:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found