Title: @Chetan Hanumantha
Name: Aeron
Date: 3/7/2012 9:25:44 AM
Comment:
Posted a bit late but your corrected regex doesn't match:
::
and does match:
1111:2222:3333:4444:5555:6666:00.00.00.00
:1.2.3.4
:6666:1.2.3.4
:5555:6666:1.2.3.4
:4444:5555:6666:1.2.3.4
Title: Working regular expression. This regular expression fixes problems mentioned below.
Name: Chetan Hanumantha
Date: 3/12/2009 8:06:05 AM
Comment:
^( (([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|
(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})|
(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})|
(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})|
(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})|
(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})|
( ([0-9A-Fa-f]{1,4}:){6} ((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3} (\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b) )|
( ([0-9A-Fa-f]{1,4}:){1,5}:((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|
(([0-9A-Fa-f]{1,4}:){1}:([0-9A-Fa-f]{1,4}:){0,4}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|
(([0-9A-Fa-f]{1,4}:){0,2}:([0-9A-Fa-f]{1,4}:){0,3}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|
(([0-9A-Fa-f]{1,4}:){0,3}:([0-9A-Fa-f]{1,4}:){0,2}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|
(([0-9A-Fa-f]{1,4}:){0,4}:([0-9A-Fa-f]{1,4}:){1}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|
(::([0-9A-Fa-f]{1,4}:){0,5}((\b((25[0-5])|(1\d{2})|(2[0-4]\d) |(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|
([0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|
(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})|
(([0-9A-Fa-f]{1,4}:){1,7}:)
)$
Title: reg ex error
Name: Chetan
Date: 3/12/2009 4:53:51 AM
Comment:
This regular expression says :1.2.3.4 as valid
which is wrong
Title: reg ex error
Name: Chetan
Date: 3/12/2009 4:52:29 AM
Comment:
This regular expression says :1.2.3.4 as valid
which is wrong
Title: reg ex error
Name: anonymous
Date: 9/13/2006 9:56:01 AM
Comment:
error in A::A:1.1.1.1
this should be valid ipv6 address
Title: Small addition to add CIDR notation
Name: Nicholas Telford
Date: 6/13/2005 11:27:45 AM
Comment:
Great regex, truly good work.
I've found no flaws in this regex so far, it seems fully compliant with the RFC.
Small note, if anyone wishes to use this regex to optionally validate an IPv6 address in CIDR notation as well, simply add the following to the end of the regex (before the trailing $ of course):
(/(1[0-1][0-9]|12[0-8]|[2-9][0-9]|1[6-9]))?