IPv4 Address Validator
June 19th, 2019 / By Andrew Currie
June 19th, 2019 / By Andrew Currie
A common programming exercise is to write some code that will validate an IP address. IPv4 addresses are displayed canonically using dot-decimal notation and they consist of four decimal numbers or octets that range from zero to 255 separated by periods.
Let’s build a simple form that will validate an IPv4 address using JavaScript and Regular Expression. To do this we are going to need three files: index.html, validator.js and style.css the web page, the JavaScript and the stylesheet, respectively.
To make the form look a little better, let’s use the 50 lines of CSS below in the stylesheet, style.css:
Once you put it all together, you will end up with a form that looks like the one below:
Click on the image above to see the IPv4 Address Validator in action.