Patrick Lambert > Sanitize-1.00 > Sanitize

Download:
Sanitize-1.00.zip

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 1.00   Source  

NAME ^

Sanitize - Returns a sanitized version of strings

SYNOPSIS ^

        use Sanitize;

        sanitize("fd gfd*#(sd)", alpha => 1);  # Returns: "fggfdsd"
        
        sanitize("The ip is 192.168.3.53:80", ip => 1);  # Returns: "192.168.3.53"
        
        sanitize("The ip is 192.168.3.53:80", port => 1);  # Returns: "80"
        
        sanitize("The ip is 192.168.3.53:80", ip => 1, port => 1);  # Returns: "192.168.3.53:80"
        
        sanitize("Blah", password => 1);  # Returns: "****"
        
        sanitize("sf d54_d <script>alert('test');", html => 1);  # Returns: "sf d54_d &lt;script&gt;alert('test');"
        
        sanitize("Some email is: joe@test.com, email me now", email => 1);  # Returns: "joe@test.com"
        
        sanitize(" some thing  ", rtrim => 1);  # Returns: " some thing"
        
        sanitize(" some thing  ", ltrim => 1);  # Returns: "some thing  "
        
        sanitize(" some thing  ", nospace => 1);  # Returns: "something"
        
        sanitize("This is a %3Cscript%3Ealert('test');", noquote => 1, noencoding => 1);  # Returns: "This is a scriptalert(test);"
        
        validate("invalid email@some!host", email => 1);  # Returns: 0
        
        validate("10.0.0.1", ip => 1);  # Returns: 1
        
        validate("invalid.ip.7.4", ip => 1);  # Returns: 0

DESCRIPTION ^

This module offers simple ways to sanitize or validate string inputs against a number of possible criteria.

METHODS ^

$output = sanitize($input, criteria1 => 0|1, criteria2 => 0|1, ..)

Returns a sanitized version of the input.

$boolean = validate($input, criteria1 => 0|1, criteria2 => 0|1, ..)

Validates whether the input matches the provided criteria.

CRITERIA ^

alpha

Matches alphanumeric characters.

hex

Matches hexadecimal characters.

number

Matches numbers, either an integer value or string containing nothing but numbers.

html

Replaces any "<" and ">" with the encoded values "&lt;" and "&gt;".

email

Matches a valid "name"@"host" string, including valid characters for both the name and host parts.

nospace

Matches any space.

rtrim

Matches any space at the end of the string.

ltrim

Matches any space at the beginning of the string.

noquote

Matches any single or double quotes.

noencoding

Matches any URL encoding such as "%00" or "%3F".

password

Replaces all characters with "*".

ip

Matches a valid "xxx.xxx.xxx.xxx" IPv4 address.

port

Matches the port part of "host":"port".

AUTHOR ^

Patrick Lambert, <dendory@live.ca>

COPYRIGHT AND LICENSE ^

Copyright (C) 2014 by Patrick Lambert

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.16.3 or, at your option, any later version of Perl 5 you may have available.

syntax highlighting: