IP address validation in javascript

In javascript, we have to do validation at client side. For that purpose we have regex [Regular Expression]. But for some complex or specific requirement we have to build some logic at our own. So here the function check whether the IP address enter in textbox is correct or not and return true or false accordingly.

Functino for IP validation in javascript.

Code :

function checkIpAdd(id)
{
	var ipAdd = document.getElementById(id).value;
	if(ipAdd.substr(0, 3) > 255 || ipAdd.substr(4, 3) > 255 || ipAdd.substr(8, 3) > 255 || ipAdd.substr(12, 3) > 255)	
                return false;
        else    return true;
}
Advertisements