commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Senthil Kumar (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (VALIDATOR-307) isValid checks if the given address is only IPV4 address and not IPV6
Date Fri, 27 Jul 2012 09:37:34 GMT

    [ https://issues.apache.org/jira/browse/VALIDATOR-307?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13423767#comment-13423767
] 

Senthil Kumar commented on VALIDATOR-307:
-----------------------------------------

This is what i'm using in my code for now, 


try {
  isValid = InetAddress.getByName(address) instanceof Inet6Address;
} catch (UnknownHostException ex) {
  isValid = false;
}

and if i had to change the InetAddressValidator.java it would look like,

{code:title=InetAddressValidator.java|borderStyle=solid}
public boolean isValid(String inetAddress) {
  boolean isValid = false;
  if(isValidInet4Address(inetAddress)){
    isValid = true;
  } else { //could it be IPV6?
    try {
      isValid = InetAddress.getByName(address) instanceof Inet6Address;
    } catch (UnknownHostException ex) {
      isValid = false;
    }
  }
  return isValid;
}
{code}
I searched stackoverflow for proper IPV6 regex validation but in vain, so this what i'm using
for now and works for my case. I assume there must be a better way to do it. Thanks.
                
> isValid checks if the given address is only IPV4 address and not IPV6
> ---------------------------------------------------------------------
>
>                 Key: VALIDATOR-307
>                 URL: https://issues.apache.org/jira/browse/VALIDATOR-307
>             Project: Commons Validator
>          Issue Type: Improvement
>          Components: Routines
>    Affects Versions: 1.4.0 Release
>            Reporter: Senthil Kumar
>              Labels: ipv6, validation
>             Fix For: 1.4.1
>
>
> function isValid(String inetAddress) checks if the given address is only IPV4 and not
IPV6. So the function returns false for a valid IPV6 address. Would it be possible to add
IPV6 validation as well?

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message