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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s