Javascript-Check IP Address using Regex


 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

 

<html>

<head>

<title>Sample Code</title>

<script type="text/javascript">

function CheckIPAddress(MyIPAddress)

{

       var CheckIP = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;

       if(CheckIP.test(MyIPAddress))

       {

             alert("Your IP Address Is Valid.");

       }

       else

       {

             alert("Your IP Address Is Not Valid.");

       }

}

</script>

</head>

<body bgcolor=#00ff00 alink=blue vlink=blue>

<FORM name="windowEvent">

       IP Address : <input type="text" name="txtipaddress" />

       <input type="button" value="Check" name="btnIPAddress" onClick="CheckIPAddress(txtipaddress.value)" />

</FORM>

</body>

</html>


Ebook Download
View all
Learn
View all