Javascript-Check IP Address using Regex

By Ghanashyam Nayak Apr 15, 2011
This code shows you that how you can check the user's given value is Valid IP Address or not using javascript on button click event.


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




<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}$/;



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




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





<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)" />




Ghanashyam Nayak
Ghanashyam Nayak

To know more about me, you can follow me on Facebook :