HTML::Widget::Constraint::Regex - Regex Constraint


HTML-Widget documentation Contained in the HTML-Widget distribution.

Index


Code Index:

NAME

Top

HTML::Widget::Constraint::Regex - Regex Constraint

SYNOPSIS

Top

    my $c = $widget->constraint( 'Regex', 'foo' );
    $c->regex(qr/^\w+$/);

DESCRIPTION

Top

Regex Constraint.

The Regex constraint always allows an undef value or an empty string. If you don't want this behaviour, also use the HTML::Widget::Constraint::All|All constraint.

METHODS

Top

regex

Arguments: qr/ regex /

validate

AUTHOR

Top

Sebastian Riedel, sri@oook.de

LICENSE

Top

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


HTML-Widget documentation Contained in the HTML-Widget distribution.
package HTML::Widget::Constraint::Regex;

use warnings;
use strict;
use base 'HTML::Widget::Constraint';

__PACKAGE__->mk_accessors(qw/regex/);

sub validate {
    my ( $self, $value ) = @_;
    my $regex = $self->regex || qr/.*/;
    return 0 if ( defined $value
        && $value ne ''
        && $value !~ $regex );
    return 1;
}

1;