SlideShare a Scribd company logo
1 of 48
Download to read offline
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
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,
});
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

What's hot

[Php] navigations
[Php] navigations[Php] navigations
[Php] navigations
Thai Pham
 
"Powerful Analysis with the Aggregation Pipeline (Tutorial)"
"Powerful Analysis with the Aggregation Pipeline (Tutorial)""Powerful Analysis with the Aggregation Pipeline (Tutorial)"
"Powerful Analysis with the Aggregation Pipeline (Tutorial)"
MongoDB
 
MongoDBと位置情報 ~地理空間インデックスの紹介
MongoDBと位置情報 ~地理空間インデックスの紹介MongoDBと位置情報 ~地理空間インデックスの紹介
MongoDBと位置情報 ~地理空間インデックスの紹介
Koji Iwazaki
 
San Francisco Java User Group
San Francisco Java User GroupSan Francisco Java User Group
San Francisco Java User Group
kchodorow
 
Object oriented mysqli connection function
Object oriented mysqli connection functionObject oriented mysqli connection function
Object oriented mysqli connection function
clickon2010
 

What's hot (20)

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

Viewers also liked

Tabla Frecuencia De Medida De Arboles
Tabla Frecuencia De Medida De ArbolesTabla Frecuencia De Medida De Arboles
Tabla Frecuencia De Medida De Arboles
Jorge Pineda
 
Tabla Frecuencia De Medida De Arboles
Tabla Frecuencia De Medida De ArbolesTabla Frecuencia De Medida De Arboles
Tabla Frecuencia De Medida De Arboles
Jorge Pineda
 
Searching the Internet
Searching the Internet Searching the Internet
Searching the Internet
guest32ae6
 

Viewers also liked (19)

Presentacio Mobile World Congress
Presentacio Mobile World CongressPresentacio Mobile World Congress
Presentacio Mobile World Congress
 
Els bolets
Els boletsEls bolets
Els bolets
 
Leadership Turlock
Leadership TurlockLeadership Turlock
Leadership Turlock
 
Attitude is everything
Attitude is everythingAttitude is everything
Attitude is everything
 
Living%20 Labs E Almirall
Living%20 Labs E AlmirallLiving%20 Labs E Almirall
Living%20 Labs E Almirall
 
Tabla Frecuencia De Medida De Arboles
Tabla Frecuencia De Medida De ArbolesTabla Frecuencia De Medida De Arboles
Tabla Frecuencia De Medida De Arboles
 
Our Library
Our LibraryOur Library
Our Library
 
lady gaga
lady gagalady gaga
lady gaga
 
Tabla Frecuencia De Medida De Arboles
Tabla Frecuencia De Medida De ArbolesTabla Frecuencia De Medida De Arboles
Tabla Frecuencia De Medida De Arboles
 
Szczecin
SzczecinSzczecin
Szczecin
 
Titi Escalante
Titi EscalanteTiti Escalante
Titi Escalante
 
Python for Scientists
Python for ScientistsPython for Scientists
Python for Scientists
 
Viatge final 4t
Viatge final 4tViatge final 4t
Viatge final 4t
 
Plucore way of using Catalyst
Plucore way of using CatalystPlucore way of using Catalyst
Plucore way of using Catalyst
 
Attitude is everything
Attitude is everythingAttitude is everything
Attitude is everything
 
自社開発をしていなかった会社が Python を選んだ理由
自社開発をしていなかった会社が Python を選んだ理由自社開発をしていなかった会社が Python を選んだ理由
自社開発をしていなかった会社が Python を選んだ理由
 
Searching the Internet
Searching the Internet Searching the Internet
Searching the Internet
 
HR
HRHR
HR
 
Corporate-Espionage
Corporate-EspionageCorporate-Espionage
Corporate-Espionage
 

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

20 modules i haven't yet talked about
20 modules i haven't yet talked about20 modules i haven't yet talked about
20 modules i haven't yet talked about
Tatsuhiko Miyagawa
 
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Masahiro Nagano
 
C A S Sample Php
C A S Sample PhpC A S Sample Php
C A S Sample Php
JH Lee
 
Introduction to CloudForecast / YAPC::Asia 2010 Tokyo
Introduction to CloudForecast / YAPC::Asia 2010 TokyoIntroduction to CloudForecast / YAPC::Asia 2010 Tokyo
Introduction to CloudForecast / YAPC::Asia 2010 Tokyo
Masahiro Nagano
 
Php code for online quiz
Php code for online quizPhp code for online quiz
Php code for online quiz
hnyb1002
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
Kang-min Liu
 

Similar to FormValidator::LazyWay で検証ルールをまとめよう (20)

Data::FormValidator Simplified
Data::FormValidator SimplifiedData::FormValidator Simplified
Data::FormValidator Simplified
 
Daily notes
Daily notesDaily notes
Daily notes
 
20 modules i haven't yet talked about
20 modules i haven't yet talked about20 modules i haven't yet talked about
20 modules i haven't yet talked about
 
Adventures in Optimization
Adventures in OptimizationAdventures in Optimization
Adventures in Optimization
 
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
 
Bag Of Tricks From Iusethis
Bag Of Tricks From IusethisBag Of Tricks From Iusethis
Bag Of Tricks From Iusethis
 
SOLID in Practice
SOLID in PracticeSOLID in Practice
SOLID in Practice
 
The Zen of Lithium
The Zen of LithiumThe Zen of Lithium
The Zen of Lithium
 
Solid in practice
Solid in practiceSolid in practice
Solid in practice
 
Php functions
Php functionsPhp functions
Php functions
 
Forms in AngularJS
Forms in AngularJSForms in AngularJS
Forms in AngularJS
 
Why Hacking WordPress Search Isn't Some Big Scary Thing
Why Hacking WordPress Search Isn't Some Big Scary ThingWhy Hacking WordPress Search Isn't Some Big Scary Thing
Why Hacking WordPress Search Isn't Some Big Scary Thing
 
C A S Sample Php
C A S Sample PhpC A S Sample Php
C A S Sample Php
 
Perl6 in-production
Perl6 in-productionPerl6 in-production
Perl6 in-production
 
Introduction to CloudForecast / YAPC::Asia 2010 Tokyo
Introduction to CloudForecast / YAPC::Asia 2010 TokyoIntroduction to CloudForecast / YAPC::Asia 2010 Tokyo
Introduction to CloudForecast / YAPC::Asia 2010 Tokyo
 
Php code for online quiz
Php code for online quizPhp code for online quiz
Php code for online quiz
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
 
全裸でワンライナー(仮)
全裸でワンライナー(仮)全裸でワンライナー(仮)
全裸でワンライナー(仮)
 
究極のコントローラを目指す
究極のコントローラを目指す究極のコントローラを目指す
究極のコントローラを目指す
 
Php.docx
Php.docxPhp.docx
Php.docx
 

Recently uploaded

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Recently uploaded (20)

Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 

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

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 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
  • 32.
  • 33.
  • 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, });
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 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]