This question already has an answer here:
i am trying to write a regular expression for validating IPv6 address,IPv4 address and host name.
My regular expression is : ^[a-zA-Z0-9./_:-]{0,128}$
it is validating everything except the ipv6 address like below :
2001:1000:1000:1000:20c:29ff:feee:a40e/64
if i remove /64, it works but with /64 its not working, need help as i am new to regular expressions.
</div>
My regex is rusty, but you need to add the pattern for "/64" and other such subnet patterns right before the $
.
You are just missing the backslash:
^[a-zA-Z0-9.\/_:-]{0,128}$
but honestly, this is validating any string between 0 and 128 characters, not only IPv6 addresses.
Look here for a solution: Regular expression that matches valid IPv6 addresses
First of all i would start with magic fact, that your regex is applying to
2001:1000:1000:1000:20c:29ff:feee:a40e/64sfddsdsfsdfsrftghyujikafjidsfhisuhfiashufiuashfuahfahffhssiauhfishaiuhsfiuahsfuhaufafas
as well - it is a valid ipV6 according to your regex:)
Here you will find more appropriate regex for ip validation and other valuable hints about validating such data.