»
Tiếng AnhTiếng PhápTiếng Việt

In - Kiểm tra IP - JavaScriptBank.com

Phiên bản đầy đủ: jsB@nk » » Kiểm tra IP
URL: https://www.javascriptbank.com/validation-ip-address.html

Kiểm tra IP © JavaScriptBank.comHiệu ứng sẽ kiểm tra">kiểm tra một dãy số do người dùng nhập vào có phải là một địa chỉ IP hay không.

Phiên bản đầy đủ: jsB@nk » » Kiểm tra IP
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-->