[
https://issues.apache.org/jira/browse/VALIDATOR-307?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13423767#comment-13423767
]
Senthil Kumar edited comment on VALIDATOR-307 at 7/27/12 9:44 AM:
------------------------------------------------------------------
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
is what i'm using for now and works for my case. I assume there must be a
better way to do it. Thanks.
was (Author: senthilkumar):
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