Re: [Exim] Wish list: isIPaddress predicate

Kezdőlap
Üzenet törlése
Válasz az üzenetre
Szerző: Nick Cleaton
Dátum:  
Címzett: Alun
CC: Exim users list
Tárgy: Re: [Exim] Wish list: isIPaddress predicate
On Fri, Sep 05, 2003 at 03:24:01PM +0100, Alun wrote:
>
> In /etc/exim/exim.pl:
>
> sub isipaddr
> {
>     return ((/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/)
>             && ($1 >= 0) && ($1 <= 255)
>             && ($2 >= 0) && ($2 <= 255)
>             && ($3 >= 0) && ($3 <= 255)
>             && ($4 >= 0) && ($4 <= 255)) ? "yes" : "no";


The >= 0 test is redundant since the regular expression doesn't allow
minus signs.

Also, '$' will match before a newline at the end of the string, so that
matches an IP address followed by a newline as well as matching an IP
address by itself.

How about:

sub isipaddr
{
    return ((/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\z/)
            && ($1 <= 255) && ($2 <= 255)
            && ($3 <= 255) && ($4 <= 255)) ? "yes" : "no";
}


--
Nick