leam hall <leamhall / gmail.com> writes:

> Any good ways of improving this as an ipv6 validator? Calling scripts
> assume it's valid unless nil.
>
> Leam
>
> ####
>
>   def self.ipv6(ip)
>     return nil if ip.match(/:::/)
>     ip_array = ip.split(":")
>     return nil if ip_array.count > 8 or ip_array.count < 1
>     ip_array.each do |octet|
>       return nil if octet.length > 4
>       return nil if octet.match(/[^[:xdigit:]]/)
>     end
>     return ip
>   end
>
> ####

It parses 1::1::1 which is invalid.

-- 
Christian Neukirchen  <chneukirchen / gmail.com>  http://chneukirchen.org


Unsubscribe: <mailto:ruby-talk-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>