-5

Please can someone help me write a regex to validate an IP BLock eg. 196.126.0.1/29.

Thanks!

Jebanisa
  • 111
  • 2
  • 15

1 Answers1

0

If you want to check that the IP is correct you can use the following expression :

 ^(\d{1,3}\.){3}\d{1,3}\/\d{1,2}$

\d{1,3}\. check that you have one to three digit following with a dot.

(\d{1,3}\.){3} repeteat the test three time.

\d{1,3}\/\d{1,2} last IP digits following with a slash and a port number (change the max number of digit if the port may be more than two digit).

dpellier
  • 1,029
  • 11
  • 9