Inputvalidator.js

// JavaScript Document

function checkDefault(elem, helperMsg)

{

if (elem.defaultValue == elem.value)

{

alert(helperMsg);

elem.focus(); // set the focus to this input

return false;

} return true;

}

function notEmpty(elem, helperMsg){

if(elem.value.length == 0){

alert(helperMsg);

elem.focus(); // set the focus to this input

return false;

} return true;

}

function isNumeric(elem, helperMsg){

var numericExpression = /^[0-9]+$/;

if(elem.value.match(numericExpression)){

return true;

}else{

alert(helperMsg);

elem.focus();

return false;

}

}



function phone(elem, helperMsg)

{

	var uInput = elem.value;	

	var numericExpression = /^[0-9]+$/;

	if(elem.value.match(numericExpression))

	{

		if(uInput.length >= 10)

		{

			return true;

		}

		else

		{

			alert(helperMsg);

			elem.focus();

			return false;

		}	

	}

	else

	{

	alert(helperMsg);

	elem.focus();

	return false;

	}

}





function isAlphabet(elem, helperMsg){

var alphaExp = /^[a-zA-Z]+$/;

if(elem.value.match(alphaExp)){

return true;

}else{

alert(helperMsg);

elem.focus();

return false;

}

}

function isAlphanumeric(elem, helperMsg){

var alphaExp = /^[0-9a-zA-Z]+$/;

if(elem.value.match(alphaExp)){

return true;

}else{

alert(helperMsg);

elem.focus();

return false;

}

}

function lengthRestriction(elem, min, max, helperMsg){

var uInput = elem.value;

if(uInput.length >= min && uInput.length <= max){

return true;

}else{

alert(helperMsg);

elem.focus();

return false;

}

}

function madeSelection(elem, helperMsg){

if(elem.value == ""){

alert(helperMsg);

elem.focus();

return false;

}else{

return true;

}

}

function emailValidator(elem, helperMsg){

var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;

if(elem.value.match(emailExp)){

return true;

}else{

alert(helperMsg);

elem.focus();

return false;

}

}// JavaScript Document



function checkurl(elem, helperMsg)

{

var urlMatch= /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/

if (elem.value != '')

{

	if(elem.value.match(urlMatch))

	{

	return true;

	}

	else

	{

	alert(helperMsg);

	elem.focus();

	return false;

	}

}

else

{

	return true;

}

}

function checkurlvideo(elem, helperMsg)

{

var urlMatch= /http:\/\/[A-Za-z0-9\.-]{3,}/

if (elem.value != '')

{

	if(elem.value.match(urlMatch))

	{

	return true;

	}

	else

	{

	alert(helperMsg);

	elem.focus();

	return false;

	}

}

else

{

	return true;

}

}



function checkurlmust(elem, helperMsg)

{

var urlMatch= /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/

	if(elem.value.match(urlMatch))

	{

	return true;

	}

	else

	{

	alert(helperMsg);

	elem.focus();

	return false;

	}

}



function checkfilename(elem, helperMsg) { 

	

if (/^[^\\\/\:\*\?\"\<\>\|\.]+(\.[^\\\/\:\*\?\"\<\>\|\.]+)+$/.test(elem.value))

 {

  return true;

 }

   else

    {

 alert(helperMsg);

 elem.focus();

 return false;

   }



}



//Supports alphabets and numbers no special characters except underscore('_') min 3 and max 20 characters. //

function titlechk(elem, helperMsg)

{

	var reg	=/[^A-Za-z&_ \d \.]/;

	

	if(reg.test(elem.value)) 

	{

		alert(helperMsg);

  		elem.focus();

  		return false;

	}

	else if (elem.value == '')

	{

		alert(helperMsg);

  		elem.focus();

  		return false;

	}

	else

 	{

		return true;

 	}

}



function checkequal(elem1, elem2,helperMsg)

{

if(elem1.value != elem2.value)

	{

		alert(helperMsg);

		elem2.focus();

		return false;			

	}

else

	{

	  return true;

	}

}



function checknotequal(elem1, elem2, helperMsg)

{

	if(elem2.value != '')

		{

		 var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;

			   if(elem2.value.match(emailExp))

				  {

						  if(elem1.value == elem2.value)

							 {

							 alert(helperMsg);

							 elem2.focus();

							 return false;			

							 }

						  else

							 {

							 return true;

							 }

				   }

			   else

				   {

				   alert(helperMsg);

				   elem2.focus();

				   return false;

				   }

		}

	else

		{

		return true;

		}

}



function nottoequal(elem1, elem2, helperMsg)

{

if(elem1.value == elem2.value)

	{

		alert(helperMsg);

		elem2.focus();

		return false;			

	}

else

	{

	  return true;

	}

}



function menutitle(elem, helperMsg)

{
var uInput = elem.value;
if(uInput.length >= 2 && uInput.length <= 20)
{
		var reg	=/[^A-Za-z0-9- ]/;
		if(reg.test(elem.value)) 
		{
			alert(helperMsg);
			elem.focus();
			return false;
		}
	
		else if (elem.value == '')
		{
			alert(helperMsg);
			elem.focus();
			return false;
		}
		else
		{
			return true;
		}
}
else
{
	alert('minimum 2 charcter & max 20 chars allowed in main menu');
	return false;
}

}

function submenutitle(elem, helperMsg)

{
var uInput = elem.value;
if(uInput.length >= 2 && uInput.length <= 50)
{
		var reg	=/[^A-Za-z0-9- ]/;
		if(reg.test(elem.value)) 
		{
			alert(helperMsg);
			elem.focus();
			return false;
		}
	
		else if (elem.value == '')
		{
			alert(helperMsg);
			elem.focus();
			return false;
		}
		else
		{
			return true;
		}
}
else
{
	alert('minimum 2 charcter & max 50 chars allowed in main menu');
	return false;
}

}
