JavaScript Program to Check IP Address Format Using Regular Expression

Write a JavaScript function to check whether a given value is valid IP value or not.

Source Code
    <title>Check for valid IP address</title>
    function checkIP()
        var re = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/
        var ip = myform.ip.value

            alert("You have entered a Valid IP address")
            alert("You have entered an Invalid IP address")
<form name="myform">
    Enter IP address <input type="text" id="ip"/>
    <input type="button" value="Submit" onclick="checkIP()"/>

"Coding Hub - Learn to code" app now available on Google Play Store