»
EnglishFrenchVietnamese

Print - Validation (IP Address) - JavaScriptBank.com

Full version: jsB@nk » Misc » Validation (IP Address)
URL: https://www.javascriptbank.com/validation-ip-address.html

Validation (IP Address) © JavaScriptBank.comVerify the value of an IP address. Check for special cases such as 0.0.0.0 and 255.255.255.255. Cool!

Full version: jsB@nk » Misc » Validation (IP Address)
URL: https://www.javascriptbank.com/validation-ip-address.html



JavaScript
<SCRIPT LANGUAGE="JavaScript">// Jay Bienvenu<!-- Beginfunction verifyIP (IPvalue) {errorString = "";theName = "IPaddress";var ipPattern = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;var ipArray = IPvalue.match(ipPattern); if (IPvalue == "0.0.0.0")errorString = errorString + theName + ': '+IPvalue+' is a special IP address and cannot be used here.';else if (IPvalue == "255.255.255.255")errorString = errorString + theName + ': '+IPvalue+' is a special IP address and cannot be used here.';if (ipArray == null)errorString = errorString + theName + ': '+IPvalue+' is not a valid IP address.';else {for (i = 0; i < 4; i++) {thisSegment = ipArray[i];if (thisSegment > 255) {errorString = errorString + theName + ': '+IPvalue+' is not a valid IP address.';i = 4;}if ((i == 0) && (thisSegment > 255)) {errorString = errorString + theName + ': '+IPvalue+' is a special IP address and cannot be used here.';i = 4;      }   }}extensionLength = 3;if (errorString == "")alert ("That is a valid IP address.");elsealert (errorString);}//  End --></script><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->


HTML
<form>IP Address:<input size=15 name="IPvalue"><input type="submit" value="Verify" onClick="verifyIP(IPvalue.value)";></form><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->