<!DOCTYPE html>
<html>
<body>
<form id="frm1" name="form1" action="/action_page.php">
IP Address: <input id="ipAddress"type="text" name="ipAddress" value="">
<br>
Host Name: <input id="hostName"type="text" name="hostName" value="">
</form>
<button onclick="ValidateIPaddress()">ValidateIPAddress</button>
<button onclick="ValidateHostName()">ValidateHostName</button>
<p>
IP Address Check :: Checks::
Example of VALID IP address
115.42.150.37
192.168.0.1
110.234.52.124
Example of INVALID IP address
210.110 – must have 4 octets
255 – must have 4 octets
y.y.y.y – only digits are allowed
255.0.0.y – only digits are allowed
666.10.10.20 – octet number must be between [0-255]
4444.11.11.11 – octet number must be between [0-255]
33.3333.33.3 – octet number must be between [0-255]
</p>
<p>
Hoste Name :: Checks::
!jkfd.com
@mfd.com
google.com
jkfd@jkfdkd.com
test.foob.ar
</p>
<script>
function ValidateIPaddress() {
var ipAddress = document.getElementById("ipAddress").value;
console.log(ipAddress);
if (/^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/.test(ipAddress)) {
return (true)
}
alert("You have entered an invalid IP address!")
return (false)
}
function ValidateHostName() {
var hostName = document.getElementById("hostName").value;
console.log(hostName);
if (/^(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])$/.test(hostName)) {
//^(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])$
///^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$/
return (true)
}
alert("You have entered an invalid Host Name !")
return (false)
}
</script>
</body>
</html>
<html>
<body>
<form id="frm1" name="form1" action="/action_page.php">
IP Address: <input id="ipAddress"type="text" name="ipAddress" value="">
<br>
Host Name: <input id="hostName"type="text" name="hostName" value="">
</form>
<button onclick="ValidateIPaddress()">ValidateIPAddress</button>
<button onclick="ValidateHostName()">ValidateHostName</button>
<p>
IP Address Check :: Checks::
Example of VALID IP address
115.42.150.37
192.168.0.1
110.234.52.124
Example of INVALID IP address
210.110 – must have 4 octets
255 – must have 4 octets
y.y.y.y – only digits are allowed
255.0.0.y – only digits are allowed
666.10.10.20 – octet number must be between [0-255]
4444.11.11.11 – octet number must be between [0-255]
33.3333.33.3 – octet number must be between [0-255]
</p>
<p>
Hoste Name :: Checks::
!jkfd.com
@mfd.com
google.com
jkfd@jkfdkd.com
test.foob.ar
</p>
<script>
function ValidateIPaddress() {
var ipAddress = document.getElementById("ipAddress").value;
console.log(ipAddress);
if (/^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/.test(ipAddress)) {
return (true)
}
alert("You have entered an invalid IP address!")
return (false)
}
function ValidateHostName() {
var hostName = document.getElementById("hostName").value;
console.log(hostName);
if (/^(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])$/.test(hostName)) {
//^(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])$
///^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$/
return (true)
}
alert("You have entered an invalid Host Name !")
return (false)
}
</script>
</body>
</html>
No comments:
Post a Comment