How to Validate IPv4 and IPv6 Prefix ?

Bhargava ram Ch
Tera Contributor

Hi,

How to Validate string IPv4 and IPv6 Prefix value On OnChange Client script.

An IPv4 address prefix. The prefix length is given by the number following the slash character and must be less than or equal to 32

ex:209.159.168.0/24,  209.159.168.7/32

An IPv6 address prefix. The prefix length is given by the number following the slash character and must be less than or equal to 128

ex:c0de::0/64, c0de::1/128

I tried with regex expression and SncIPNetworkV4.validate(), but no luck.  

Thanks,

Bhargava

6 REPLIES 6

Jaspal Singh
Mega Patron
Mega Patron

Hi Chekti,

 

Few days ago there was something similar to this case from other community user that was answered.

Kindly give link a check for reference. 

The linked thread won't solve this issue because the offered solution doesn't take into account the prefix (e.g. "/24"). Question in this thread explicitly is about regular expression on validating v4 and v6 ip addresses with prefix.