| Data-Validate-Japanese documentation | Contained in the Data-Validate-Japanese distribution. |
Data::Validate::Japanese - Validate Japanese Input
use Data::Validate::Japanese;
my $dvj = Data::Validate::Japanese->new;
$ok = $dvj->is_hiragana($data);
$ok = $dvj->is_katakana($data);
$ok = $dvj->is_kanji($data);
$ok = $dvj->is_h_katakana($data);
$dvj->contains_only($value, {
hiragana => 1,
katakana => 1,
kanji => 1,
h_katakana => 1,
ascii => 1
});
Data::Validate::Japanese aims to be the base (or at least, the common link between) the myriad different data validator infrastructures, and their Japanese-specific extensions. There are just too many validators with too many different interfaces, but it's not like the core handling of Japanese characters change.
All methods return true or false unless otherwise stated. All methods also expect Japanese characters that have successfully been decoded to Perl's internal unicode format.
Creates a new instance of Data::Validate::Japanese
Checks if a value contains half-width katakana only. Returns true or false
Checks if a value contains half-width katakana only. Returns true or false
Checks if a value contains half-width katakana only. Returns true or false
Checks if a value contains half-width katakana only. Returns true or false
Checks if a value contains only ascii
Checks if a value contains characters within the range from the list of candidates
Copyright (c) 2007 Daisuke Maki <daisuke@endeworks.jp>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| Data-Validate-Japanese documentation | Contained in the Data-Validate-Japanese distribution. |
# $Id: /mirror/perl/Data-Validate-Japanese/trunk/lib/Data/Validate/Japanese.pm 2553 2007-09-19T01:14:58.848056Z daisuke $ # # Copyright (c) 2007 Daisuke Maki <daisuke@endeworks.jp> # All rights reserved. package Data::Validate::Japanese; use strict; use warnings; use 5.008; use vars qw($VERSION); $VERSION = '0.01001'; my %regexps = ( katakana => qr(\p{InKatakana}), hiragana => qr(\p{InHiragana}), kanji => qr(\p{InCJKUnifiedIdeographs}), h_katakana => qr(\p{InHalfwidthAndFullwidthForms}), ascii => qr([[:ascii]]) ); sub new { bless {}, shift; } { foreach my $type (keys %regexps) { eval <<" EOSUB"; sub is_$type { my (\$self, \$value, \$opts) = \@_; \$self->contains_only(\$value, { $type => 1 }); } EOSUB die if $@; } } sub contains_only { my ($self, $value, $opts) = @_; $opts ||= {}; my $re = do { my $str = sprintf( '^(?:%s)$', join('|', map { "$regexps{$_}+" } grep { $opts->{$_} } keys %regexps) ); qr($str); }; return $value =~ /$re/; } 1; __END__