You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by allen haim <al...@netherrealm.net> on 2005/06/22 23:06:12 UTC

Form Validation

Gerald, is it possible this is a bug:

I notice that your validation for the Number type uses this regex:

/^\s*[0-9+-.][0-9.eE]*\s*$/

However, that fails on a value such as 9.516e-5, which is a valid float.

I believe you need to add a negative sign to the second character class:

/^\s*[0-9+-.][0-9.eE-]*\s*$/

This regex is still a little too lax, because it will allow malformed numbers
like 

9.5e5e-3 

through. 


--------

Also, I am successfully using the following rule:

$rules = [
    [
        -key    => 'user_seq',
        -name   => 'User-inputted sequence',
        emptyok     => 1,
        -msg => 'blah blah blah',
        matches_regex       => "^\\s*(>.+\\n)?[\\s$NT]+\$",
    ]
];

Note that it's 'matches_regex', not 'matches_regex_js'. In the docs it says
that this shouldn't work on the client side, but it does.

What is the difference between perl regular expressions and javascript ones?

Yours

Allen

p.s. The SetupSession/GetSession stuff is working great -- I will have more
to say on that in a bit. 

-- 



slash is the only person who deserves a slash.  

-stephen handley


---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


RE: Form Validation

Posted by Gerald Richter <ri...@ecos.de>.
> 
> Gerald, is it possible this is a bug:
> 
> I notice that your validation for the Number type uses this regex:
> 
> /^\s*[0-9+-.][0-9.eE]*\s*$/
> 
> However, that fails on a value such as 9.516e-5, which is a 
> valid float.
> 
> I believe you need to add a negative sign to the second 
> character class:
> 
> /^\s*[0-9+-.][0-9.eE-]*\s*$/
> 

Yes, you are right

> This regex is still a little too lax, because it will allow 
> malformed numbers like 
> 
> 9.5e5e-3 
> 
> through. 
> 

Yes, thats correct, patches are welcome :-)


> 
> --------
> 
> Also, I am successfully using the following rule:
> 
> $rules = [
>     [
>         -key    => 'user_seq',
>         -name   => 'User-inputted sequence',
>         emptyok     => 1,
>         -msg => 'blah blah blah',
>         matches_regex       => "^\\s*(>.+\\n)?[\\s$NT]+\$",
>     ]
> ];
> 
> Note that it's 'matches_regex', not 'matches_regex_js'. In 
> the docs it says that this shouldn't work on the client side, 
> but it does.
> 
> What is the difference between perl regular expressions and 
> javascript ones?
> 

Perl Regex are much more powerfull, so if you use "simple" pattern it will
work within both, some more complex things are only working in Perl. In such
cases you can use different regexes by using matches_regex_perl and
matches_regex_js .


> 
> p.s. The SetupSession/GetSession stuff is working great -- I 
> will have more to say on that in a bit. 
> 

Great!

Gerald


---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org