NAME
Data::FormValidator::Constraints::Words - Data constraints for word inputs.
SYNOPSIS
use Data::FormValidator::Constraints::Words;
my $rv = Data::FormValidator->check(\%input, {
real_name => realname(),
basic_words => basicwords(),
simple_words => simplewords(),
print_safe => printsafe(),
paragraph => paragraph(),
username => username(),
password => password(),
},
# or, use the regular functions
my $rv = Data::FormValidator->check(\%input, {
comments => sub {
my($dfv, $value) = @_;
return $dfv->match_paragraph($value);
}
});
DESCRIPTION
Data::FormValidator::Constraints::Words
provides several methods that can be used to generate constraint closures for use with Data::FormValidator
for the purpose of validating textual input.
CHARACTER SETS
In the methods below several character code ranges are specified, below is a quick guide to what those ranges represent:
Dec Oct Hex Description
---------------------------------------------------------
32-47 040-057 20-2F ASCII symbols
48-57 060-071 30-39 ASCII numerals
58-64 072-100 3A-40 ASCII symbols
65-90 101-132 41-5A ASCII uppercase alphabetics
91-96 133-140 5B-60 ASCII symbols
97-122 141-172 61-7A ASCII lowercase alphabetics
123-126 173-176 7B-7E ASCII symbols
128-159 200-237 80-9F Extended symbols (unsupported in HTML4 standard)
160-191 240-277 A0-BF Extended symbols
192-255 300-377 C0-FF Extended alphabetics
The above table is based on the ISO Latin 1 (ISO 8859-1) set of encodings. The character range of 128-159 has no corresponding HTML entity encodings, and are considered control characters in the ISO Latin 1 character set. See http://www.ascii-code.com/ for more details.
If you wish to override these settings, subclass this module and set the appropriate values for the following regular expression settings:
$REALNAME = q/\-\s\w.,\'\xC0-\xFF/;
$BASICWORDS = q/\-\s\w.,\'\"&;:\?\#\xC0-\xFF/;
$SIMPLEWORDS = q/\-\s\w.,\'\"&;:\?\#~\+=\(\)\[\]\{\}<>\/!\xC0-\xFF/;
$PRINTSAFE = q/\s\x20-\x7E\xA0-\xFF/;
$PARAGRAPH = q/\s\x20-\x7E\xA0-\xFF/;
$USERNAME = q/\x30-\x39\x41-\x5A\x61-\x7A\x8A\x8C\x8E\x9A\x9C\x9E\x9F\xC0-\xFF/;
$PASSWORD = q/\x21-\x7E\x80\x82-\x8C\x8E\x91-\x9C\x9E-\x9F\xA1-\xAC\xAE-\xFF/;
Note that these are used within a character class, so characters such as '-' must be escaped.
Although here PRINTSAFE and PARAGRAPH are the same, they may not be when subclassed.
Both USERNAME and PASSWORD exclude whitespace characters, while USERNAME also excludes all symbol characters.
METHODS
realname
The realname methods allows commonly used characters within a person's name to be used. Also restricts the string length to 128 characters. Acceptable characters must match the $REALNAME regular expression.
realname
valid_realname
match_realname
basicwords
The basicwords methods allow a restricted character set to match simple strings, such as reference codes. Acceptable characters must match the $BASICWORDS regular expression:
basicwords
valid_basicwords
match_basicwords
simplewords
The simplewords methods allow commonly used characters within simple text box input, such as for titles. Acceptable characters must match the $SIMPLEWORDS regular expression.
simplewords
valid_simplewords
match_simplewords
printsafe
The printsafe methods restrict characters to those non-control characters within the character set. Acceptable characters must match the $PRINTSAFE regular expression.
printsafe
valid_printsafe
match_printsafe
paragraph
The paragraph methods allows for a larger range of characters that would be expected to appear in a textarea input, such as a news story or a review. Acceptable characters must match the $PARAGRAPH regular expression:
paragraph
valid_paragraph
match_paragraph
username
The username methods allows for a restricted range of letter only characters that would be expected to appear in a username style input field. Acceptable characters must match the $USERNAME regular expression:
username
valid_username
match_username
password
The password methods allows for a restricted range of characters that would be expected to appear in a password style input field. Acceptable characters must match the $PASSWORD regular expression:
password
valid_password
match_password
NOTES
Although Data-FormValidator is not a dependency, it is expected that this module will be used as part of DFV's constraint framework.
This module was originally written as part of the Labyrinth website management tool.
SEE ALSO
AUTHOR
Barbie, <barbie@missbarbell.co.uk> for Miss Barbell Productions, http://www.missbarbell.co.uk/
COPYRIGHT & LICENSE
Copyright (C) 2002-2014 Barbie for Miss Barbell Productions
All Rights Reserved.
This distribution is free software; you can redistribute it and/or
modify it under the Artistic Licence v2.