Skip to content

Instantly share code, notes, and snippets.

@andrewjcurrie
Created May 10, 2023 00:24
Show Gist options
  • Save andrewjcurrie/b3fb4a56585e649214d135a897e6df73 to your computer and use it in GitHub Desktop.
Save andrewjcurrie/b3fb4a56585e649214d135a897e6df73 to your computer and use it in GitHub Desktop.
IPv4 Address Validator
function ValidateIPaddress(inputText) {
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]?)$/;
if (inputText.value.match(ipformat)) {
alert("You entered a valid IPv4 address.");
document.ipform.ipaddr.focus();
return false;
} else {
alert("You entered an invalid IPv4 address.");
document.ipform.ipaddr.focus();
return false; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment