develooper Front page | perl.wxperl.users | Postings from February 2013

Re: Vaiidators

Thread Previous | Thread Next
Johan Vromans
February 13, 2013 07:43
Re: Vaiidators
Message ID:
James Lynes <> writes:

> print Dumper($timeval) says:
>     $VAR1 = bless( {
>                  'data' => \'10:00',
>                  'validate' => qr/(?^:(\d+:))/
>                }, 'LCDAlarmClockDialog::Validator' );
> 1. Not sure what the pre-pended ?^: means. It was added by
> Wx::Perl::TextValidator
> 2. I have tried a number of regex strings:
>       (\d+)              allows entry of numbers
>       (:)                  allows entry of colons
>       (\d+:)             allows no entry at all
>      (\d+:\d+)         allows no entry at all
>      (\d{2,}:\d{2,})    allows no entry at all

It's a long time ago that I playes with Validators, but I seem to recall
that there was something with the moment the test was applied. 
The validator is really a filter, so it restrics what characters can be
input. When you try (\d+:) then youy're matching more than one character
against the input, which will always fail since the input initially is
empty and the first character will never match the pattern.

So the validator pattern should be sort of character class, e.g. [\d:]
and you need an additional end-form validator ^(\d{2,}:\d{2,})$ in

-- Johan

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About