I have two function in JS that check if a typed input is a valid IPv4. This is the regex that I got from @Abana Clara from this question: How to validate IP Address on multiple inputs?
var ipformat = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
I would like to add to this regex the possibility to also validate CIDR IPv4 addresses.
Please note that both of the following addresses should be valid:
192.168.1.20
192.168.1.20/24