Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

HTML5 Validation Rules

branch: master

Checking in changes prior to tagging of version 0.02.

Changelog diff is:

diff --git a/Changes b/Changes
index a9f3eb5..7ff4513 100644
--- a/Changes
+++ b/Changes
@@ -1,4 +1,9 @@
 Revision history for Perl extension HTML5::ValidationRules

+0.02    2012-10-20
+        [DISTRIBUTING ISSUE]
+        - distribute with new Module::Install
+        - http://weblog.bulknews.net/post/33907905561/do-not-ship-modules-with-module-install-1-04
+
 0.01    Tue Nov  1 12:54:19 2011
         - original version
latest commit 5fe6ace371
Kentaro Kuribayashi authored October 20, 2012
Octocat-spinner-32 lib
Octocat-spinner-32 t HTML_RANGE is an alias for HTML_NUMBER November 04, 2011
Octocat-spinner-32 xt
Octocat-spinner-32 .gitignore Ignore November 03, 2011
Octocat-spinner-32 .shipit initial commit November 01, 2011
Octocat-spinner-32 Changes Checking in changes prior to tagging of version 0.02. October 20, 2012
Octocat-spinner-32 MANIFEST modified MANIFEST November 04, 2011
Octocat-spinner-32 MANIFEST.SKIP
Octocat-spinner-32 Makefile.PL Checking in changes prior to tagging of version 0.02. October 20, 2012
Octocat-spinner-32 README updated manifest/readme November 04, 2011
README
NAME
    HTML::ValidationRules - Extract Validation Rules from HTML Form Element

SYNOPSIS
      # form.html
      <!doctype html>
      <html>
        <head>
          <meta charset="UTF-8">
          <title>HTML5::ValidationRules</title>
        </head>
        <body>
          <form method="post" action="/post">
            <input type="text" name="text" pattern="[A-Za-z0-9]+" maxlength="255" />
            <input type="url" name="url" maxlength="255" required />
            <input type="email" name="email" maxlength="255" required="required" />
            <input type="number" name="number" min="200" max="800" />
            <textarea name="textarea" maxlength="1000" required></textarea>
            <input type="range"" name="range" min="20" max="80" />
            <input type="submit" value="submit" />
          </form>
        </body>
      </html>

      # in your code
      use HTML::ValidationRules;

      my $parser = HTML::ValidationRules->new;
      my $rules  = $parser->load_rules(file => 'form.html');

      # rules will be extracted as follows:
      # [
      #     text     => [ [ HTML_PATTERN => '[A-Za-z0-9]+' ], [ HTML_MAXLENGTH => 255 ] ],
      #     url      => [ HTML_URL    => [ HTML_MAXLENGTH => 255 ], 'NOT_BLANK'         ],
      #     email    => [ HTML_EMAIL  => [ HTML_MAXLENGTH => 255 ], 'NOT_BLANK'         ],
      #     number   => [ HTML_NUMBER => [ HTML_MIN => 200 ], [ HTML_MAX => 800 ]       ],
      #     textarea => [ [ HTML_MAXLENGTH => 1000 ], 'NOT_BLANK'                       ],
      #     range    => [ HTML_RANGE => [ HTML_MIN => 20 ], [ HTML_MAX => 80 ]          ],
      # ]

      # then do validation using FormValidator::Simple
      use FormValidator::Simple qw(HTML);

      my $query  = CGI->new;
      my $result = FormValidator::Simple->check($query => $rules);

      # or FormValidator::Lite
      use FormValidator::Lite;
      FormValidator::Lite->load_constraints('HTML');

      my $query     = CGI->new;
      my $validator = FormValidator::Lite->new($query);
      my $result    = $validator->check(@$rules);

DESCRIPTION
    HTML::ValidationRules regards HTML form element as validation rules
    definition and extract rules from it.

WARNING
    This software is under the heavy development and considered ALPHA
    quality now. Things might be broken, not all features have been
    implemented, and APIs will be likely to change. YOU HAVE BEEN WARNED.

METHODS
  new(%args)
          my $parser = HTML::ValidationRules->new(
              options => { ... } #=> options for HTML::Parser
          );

        Returns a new HTML::ValidationRules object.

  load_rules(%args)
          my $rules = $parser->load_rules(file => 'form.html');

        Parse HTML and extract validation rules from form element (defined
        as HTML5 client-side form validation spec, but not all of them).
        $rules has compatible form as args for FormValidator::Simple and
        FormValidator::Lite's check() method.

        %args are supposed to contain one of them below:

        *   file

            Path to a file or filehandle.

        *   html

            String of HTML.

SUPPORTED ATTRIBUTES
    HTML "input", "textare", and "select" elements can have some attributes
    related to validation. This module hasn't support all the attrs defined
    in HTML5 spec yet, just has done below so far:

    *   max (input)

    *   maxlength (input, textarea)

    *   min (input)

    *   pattern (input)

    *   required (input, textarea, select)

    *   type (input)

        *   type:url

        *   type:email

        *   type:number

        *   type:range

BUGS
    The "pattern" attribute is interpreted as a Perl regular expression, not
    a JavaScript regular expression as defined by the HTML spec. Please use
    common subset of Perl and JavaScript regular expression languages to
    keep compatibility with both Perl and Web browsers.

AUTHORS
    *   Kentaro Kuribayashi <kentarok@gmail.com>

    *   Wakaba <w@suika.fam.cx>

SEE ALSO
    *   <http://www.whatwg.org/specs/web-apps/current-work/multipage/#client
        -side-form-validation>

    *   <http://www.whatwg.org/specs/web-apps/current-work/multipage/#the-in
        put-element>

    *   <http://www.whatwg.org/specs/web-apps/current-work/multipage/#the-te
        xtarea-element>

LICENSE
    Copyright (C) Kentaro Kuribayashi

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

Something went wrong with that request. Please try again.