NAME

Validator::Custom::HTMLForm - HTML Form Validator

SYNOPSIS

use Validator::Custom::HTMLForm;

# Data
my $data = {
    name => 'ABCD',
    age =>  29,

    mail1  => 'name@gmail.com',
    mail2  => 'name@gmail.com',

    year   => 2005,
    month  =>   11,
    day    =>   27,
}

# Validation rule
my $rule = [
    name => [
        'not_blank',
        'ascii',
        {length => [1, 30]}
    ],
    age => [
        'not_blank',
        'int'
    ],
    
    mail1  => [
        'trim',
        'not_blank',
        'email_loose'
    ],
    mail2  => [
        'not_blank',
        'email_loose'
    ],
    
    [qw/mail1 mail2/] => [
        'duplication'
    ],
    
    { date  => ['year',  'month', 'day'] } => [
        'date'
    ]
]

# Create validator object
my $vc = Validator::Custom::HTMLForm->new;

# Validate
my $result = $vc->validate($data, $rule);

DESCRIPTION

Validator::Custom::HTMLForm is HTML form validator. This class inherit all methods from Validator::Custom. If you know usage of This module, See Validator::Custom documentation.

METHODS

This module is Validator::Custom subclass. All methods of Validator::Custom is available.

CONSTRAINT FUNCTIONS

Validator::Custom::HTMLForm inherit all constraints from Validator::Custom and Validator::Custom::Trim.

email

Check with Email::Valid.

my $data = {mail => 'a@somehost.com'};
my $rule => [
    mail => [
        'email'
    ]
];

email_mx

check with Email::Valid, including mx check.

my $data = {mail => 'a@somehost.com'};
my $rule => [
    mail => [
        'email_mx'
    ]
];

email_loose

check with Email::Valid::Loose.

my $data = {mail => 'a.@somehost.com'};
my $rule => [
    mail => [
        'email_loose'
    ]
];

email_loose_mx

my $data = {mail => 'a.@somehost.com'};
my $rule => [
    mail => [
        'email_loose'
    ]
];

date

check with Date::Calc

my $data = {year => '2009', month => '12', day => '13'};
my $rule => [
    {date => [qw/year month day/]} => [
        'date'
    ]
];

$result->data->{date}; # 2009-12-13 00:00:00

You can specify options

# Convert DateTime object
my $rule => [
    {date => [qw/year month day/]} => [
        {'date' => {'datetime_class' => 'DateTime', time_zone => 'Asia/Tokyo'}}
    ]
];

$result->data->{date}; # DateTime object


# Convert Time::Piece object
my $rule => [
    {date => [qw/year month day/]} => [
        {'date' => {'datetime_class' => 'Time::Piece'}}
    ]
];

$result->data->{date}; # Time::Piece object

time

check with Date::Calc

my $data = {hour => '12', minute => '40', second => '13'};
my $rule => [
    [qw/hour minute second/] => [
        'time'
    ]
];

datetime

check with Date::Calc

my $data = {
    year => '2009', month => '12',  day => '13'
    hour => '12',   minute => '40', second => '13'
};
my $rule => [
    {datetime => [qw/year month day hour minute second/]} => [
        'datetime'
    ]
];

$result->data->{datetime}; # 2009-12-13 12:40:13

You can specify options

# Convert DateTime object
my $rule => [
    {datetime => [qw/year month day hour minute second/]} => [
        {'datetime' => {'datetime_class' => 'DateTime', time_zone => 'Asia/Tokyo'}}
    ]
];

$result->data->{date}; # DateTime object


# Convert Time::Piece object
my $rule => [
    {datetime => [qw/year month day hour minute second/]} => [
        {'datetime' => {'datetime_class' => 'Time::Piece'}}
    ]
];

$result->data->{date}; # Time::Piece object

datetime_strptime

check with DateTime::Format::Strptime.

my $data = {datetime => '2006-04-26T19:09:21+0900'};

my $rule => [
    datetime => [
        {'datetime_strptime' => '%Y-%m-%dT%T%z'}
    ]
];

$result->data->{datetime}; # DateTime object

datetime_format

check with DateTime::Format::***. for example, DateTime::Format::HTTP, DateTime::Format::Mail, DateTime::Format::MySQL and etc.

my $data = {datetime => '2004-04-26 19:09:21'};

my $rule = [
    datetime => [
        {datetime_format => 'MySQL'}
    ]
];

in_array

check if the food ordered is in menu

my $rule = [
    food => [
        {in_array => [qw/sushi bread apple/]}
    ]
];

STABILITY

Validator::Custom::HTMLForm is stable. All constraints keep backword compatible.

AUTHOR

Yuki Kimoto, <kimoto.yuki at gmail.com>

COPYRIGHT & LICENSE

Copyright 2009 Yuki Kimoto, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.