SlideShare a Scribd company logo
FormValidator::LazyWay で検証ルールをまとめよう
FormValidator::LazyWay で検証ルールをまとめよう
FormValidator::LazyWay で検証ルールをまとめよう
FormValidator::LazyWay で検証ルールをまとめよう
FormValidator::LazyWay で検証ルールをまとめよう
FormValidator::LazyWay で検証ルールをまとめよう
FormValidator::LazyWay で検証ルールをまとめよう
FormValidator::LazyWay で検証ルールをまとめよう
FormValidator::LazyWay で検証ルールをまとめよう
FormValidator::LazyWay で検証ルールをまとめよう
FormValidator::LazyWay で検証ルールをまとめよう
FormValidator::LazyWay で検証ルールをまとめよう
FormValidator::LazyWay で検証ルールをまとめよう
FormValidator::LazyWay で検証ルールをまとめよう
FormValidator::LazyWay で検証ルールをまとめよう
FormValidator::LazyWay で検証ルールをまとめよう
FormValidator::LazyWay で検証ルールをまとめよう
FormValidator::LazyWay で検証ルールをまとめよう
FormValidator::LazyWay で検証ルールをまとめよう
FormValidator::LazyWay で検証ルールをまとめよう
FormValidator::LazyWay で検証ルールをまとめよう
FormValidator::LazyWay で検証ルールをまとめよう
FormValidator::LazyWay で検証ルールをまとめよう
FormValidator::LazyWay で検証ルールをまとめよう
my $config = {
    rules => [ 'Email',    'String' ],
    setting => {
        strict => {
            email     =>   {
                rule =>    ['Email#email']
            },
            password =>    {
                rule =>    [
                    {      'String#length' => {
                               'min' => '4',
                               'max' => '12'
                           }
                        },
                        'String#ascii'
                   ]
              },
          }
     },
     lang    => 'ja',
     labels => {
          ja => {
              email      => '            ',
              password => '         '
          }
     },
};
use FormValidator::LazyWay;

my $fv = FormValidator::LazyWay->new($config);
my $result = $fv->check($q, {
    required => [qw/nickname email password/],
    optional => [qw/message/]
});
my $result = $fv->check($q, {
    required => [qw/title/],
    optional => [qw/body/]
});




my $result = $fv->check($q, {
    optional => [qw/title body/]
});
my $result = $fv->check($q, {
    required => [qw/nickname email password/],
    optional => [qw/message/]
});

if ( $result->has_error ) {
    print Dumper $result->error_message;

    # output
    #$VAR1 = {
    # 'email' => '                     ',
    #    'password' => '           4        12   '
    #};
}
else {

    # OK!
    print Dumper $result->valid;
}
setting:                      my $result = $fv->check( $cgi,
  strict:                         {   required => [qw/email/],
    email:                            level => {
                                          email => 'loose'
      rule:
                                      }
        - Email#email
                                  }
  loose:                      );
    email:
      rule:
        - Email#email_loose
setting:
  regexp_map:
    '_id$':
      rule:
         - Number#integer
merge:
  date:
    format: "%04d-%02d-%02d"
    fields:
       - year
       - month
       - day
strict:
  date:
    rule:
       - DateTime#date
FormValidator::LazyWay で検証ルールをまとめよう
FormValidator::LazyWay で検証ルールをまとめよう
setting:
  strict:
    date:
      filter:
         - Unify#hyphen
      rule:
         - DateTime#date
      fix:
         - DateTime#format:
             - '%Y-%m-%d'
my $result = $fv->check($q, {
    required => [qw/nickname email password/],
    optional => [qw/message/]
});

if ( $result->has_error ) {
    print Dumper $res->error_message;
}

#                   DateTime
print $result->valid->{date};
my $result = $fv->check($q, {
    required => [qw/nickname email password/],
    optional => [qw/message/]
});

$result->custom_invalid(
  'email_not_unique',
  '                                     '
);

if ( $res->has_error ) {
    print Dumper $res->error_message;
}
my $wants_to_validate = {
    nickname => 'vkgtaro',
    email    => 'vkg.taro@gmail.com',
    password => 'mypass',
};

my $result = $fv->check($q, {
    required => [qw/nickname email password/],
    optional => [qw/message/],
    custom_parameters => $wants_to_validate,
});
FormValidator::LazyWay で検証ルールをまとめよう
FormValidator::LazyWay で検証ルールをまとめよう
FormValidator::LazyWay で検証ルールをまとめよう
FormValidator::LazyWay で検証ルールをまとめよう
FormValidator::LazyWay で検証ルールをまとめよう
FormValidator::LazyWay で検証ルールをまとめよう
messages :
    ja :
         rule_message : __field__     __rule__
        rule :
            Email#email   :
            String#length : $_[min]              $_[max]
messages :
    ja :
         rule_message : __field__     __rule__
        rule :
            Email#email   :
            String#length : $_[min]              $_[max]
FormValidator::LazyWay で検証ルールをまとめよう
FormValidator::LazyWay で検証ルールをまとめよう
FormValidator::LazyWay で検証ルールをまとめよう

More Related Content

ZIP
TerminalでTwitter
PPTX
Topological indices (t is) of the graphs to seek qsar models of proteins com...
PDF
与 PHP 和 Perl 使用 MySQL 数据库
PDF
PDF
C++ Programming - 6th Study
PDF
C++ Programming - 7th Study
PPTX
Database Management - Lecture 4 - PHP and Mysql
PDF
Groovy as a scripting language
TerminalでTwitter
Topological indices (t is) of the graphs to seek qsar models of proteins com...
与 PHP 和 Perl 使用 MySQL 数据库
C++ Programming - 6th Study
C++ Programming - 7th Study
Database Management - Lecture 4 - PHP and Mysql
Groovy as a scripting language

What's hot (20)

PPTX
PHP Lecture 4 - Working with form, GET and Post Methods
PDF
First step of Performance Tuning
PPTX
PHP Lecture 6 - Php file uploading
PDF
Dependency Injection
PDF
[Php] navigations
TXT
[Php] navigations
PPTX
ETL for Pros: Getting Data Into MongoDB
PDF
introduction to Django in five slides
PDF
MongoDB a document store that won't let you down.
PPTX
"Powerful Analysis with the Aggregation Pipeline (Tutorial)"
PDF
Php 2
PDF
Path::Tiny
PDF
MongoDB World 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pipeline Em...
PDF
MongoDB .local Bengaluru 2019: Aggregation Pipeline Power++: How MongoDB 4.2 ...
PDF
MongoDBと位置情報 ~地理空間インデックスの紹介
PDF
San Francisco Java User Group
PDF
Jina Bolton
PPTX
8. Php MongoDB stergerea unui document
DOC
Object oriented mysqli connection function
PHP Lecture 4 - Working with form, GET and Post Methods
First step of Performance Tuning
PHP Lecture 6 - Php file uploading
Dependency Injection
[Php] navigations
[Php] navigations
ETL for Pros: Getting Data Into MongoDB
introduction to Django in five slides
MongoDB a document store that won't let you down.
"Powerful Analysis with the Aggregation Pipeline (Tutorial)"
Php 2
Path::Tiny
MongoDB World 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pipeline Em...
MongoDB .local Bengaluru 2019: Aggregation Pipeline Power++: How MongoDB 4.2 ...
MongoDBと位置情報 ~地理空間インデックスの紹介
San Francisco Java User Group
Jina Bolton
8. Php MongoDB stergerea unui document
Object oriented mysqli connection function
Ad

Viewers also liked (19)

KEY
Presentacio Mobile World Congress
PPT
Els bolets
PPT
Leadership Turlock
PPSX
Attitude is everything
PDF
Living%20 Labs E Almirall
XLS
Tabla Frecuencia De Medida De Arboles
PPT
Our Library
PPTX
lady gaga
XLS
Tabla Frecuencia De Medida De Arboles
PPT
Szczecin
PPT
Titi Escalante
PPTX
Python for Scientists
PPT
Viatge final 4t
PDF
Plucore way of using Catalyst
PPSX
Attitude is everything
KEY
自社開発をしていなかった会社が Python を選んだ理由
PPT
Searching the Internet
PPTX
Corporate-Espionage
Presentacio Mobile World Congress
Els bolets
Leadership Turlock
Attitude is everything
Living%20 Labs E Almirall
Tabla Frecuencia De Medida De Arboles
Our Library
lady gaga
Tabla Frecuencia De Medida De Arboles
Szczecin
Titi Escalante
Python for Scientists
Viatge final 4t
Plucore way of using Catalyst
Attitude is everything
自社開発をしていなかった会社が Python を選んだ理由
Searching the Internet
Corporate-Espionage
Ad

Recently uploaded (20)

PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
Hindi spoken digit analysis for native and non-native speakers
PPTX
Tartificialntelligence_presentation.pptx
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Heart disease approach using modified random forest and particle swarm optimi...
PDF
project resource management chapter-09.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
1 - Historical Antecedents, Social Consideration.pdf
PDF
Mushroom cultivation and it's methods.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Hybrid model detection and classification of lung cancer
PDF
Zenith AI: Advanced Artificial Intelligence
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
August Patch Tuesday
PDF
NewMind AI Weekly Chronicles - August'25-Week II
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Group 1 Presentation -Planning and Decision Making .pptx
Hindi spoken digit analysis for native and non-native speakers
Tartificialntelligence_presentation.pptx
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
Programs and apps: productivity, graphics, security and other tools
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Heart disease approach using modified random forest and particle swarm optimi...
project resource management chapter-09.pdf
Unlocking AI with Model Context Protocol (MCP)
1 - Historical Antecedents, Social Consideration.pdf
Mushroom cultivation and it's methods.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
A comparative analysis of optical character recognition models for extracting...
Hybrid model detection and classification of lung cancer
Zenith AI: Advanced Artificial Intelligence
SOPHOS-XG Firewall Administrator PPT.pptx
August Patch Tuesday
NewMind AI Weekly Chronicles - August'25-Week II

FormValidator::LazyWay で検証ルールをまとめよう

  • 25. my $config = { rules => [ 'Email', 'String' ], setting => { strict => { email => { rule => ['Email#email'] }, password => { rule => [ { 'String#length' => { 'min' => '4', 'max' => '12' } }, 'String#ascii' ] }, } }, lang => 'ja', labels => { ja => { email => ' ', password => ' ' } }, };
  • 26. use FormValidator::LazyWay; my $fv = FormValidator::LazyWay->new($config); my $result = $fv->check($q, { required => [qw/nickname email password/], optional => [qw/message/] });
  • 27. my $result = $fv->check($q, { required => [qw/title/], optional => [qw/body/] }); my $result = $fv->check($q, { optional => [qw/title body/] });
  • 28. my $result = $fv->check($q, { required => [qw/nickname email password/], optional => [qw/message/] }); if ( $result->has_error ) { print Dumper $result->error_message; # output #$VAR1 = { # 'email' => ' ', # 'password' => ' 4 12 ' #}; } else { # OK! print Dumper $result->valid; }
  • 29. setting: my $result = $fv->check( $cgi, strict: { required => [qw/email/], email: level => { email => 'loose' rule: } - Email#email } loose: ); email: rule: - Email#email_loose
  • 30. setting: regexp_map: '_id$': rule: - Number#integer
  • 31. merge: date: format: "%04d-%02d-%02d" fields: - year - month - day strict: date: rule: - DateTime#date
  • 34. setting: strict: date: filter: - Unify#hyphen rule: - DateTime#date fix: - DateTime#format: - '%Y-%m-%d'
  • 35. my $result = $fv->check($q, { required => [qw/nickname email password/], optional => [qw/message/] }); if ( $result->has_error ) { print Dumper $res->error_message; } # DateTime print $result->valid->{date};
  • 36. my $result = $fv->check($q, { required => [qw/nickname email password/], optional => [qw/message/] }); $result->custom_invalid( 'email_not_unique', ' ' ); if ( $res->has_error ) { print Dumper $res->error_message; }
  • 37. my $wants_to_validate = { nickname => 'vkgtaro', email => 'vkg.taro@gmail.com', password => 'mypass', }; my $result = $fv->check($q, { required => [qw/nickname email password/], optional => [qw/message/], custom_parameters => $wants_to_validate, });
  • 44. messages : ja : rule_message : __field__ __rule__ rule : Email#email : String#length : $_[min] $_[max]
  • 45. messages : ja : rule_message : __field__ __rule__ rule : Email#email : String#length : $_[min] $_[max]