JavaScript Validator


<script language="javascript" type="text/livescript">
function validate()
{
	if(document.getElementById('nickname').value.search(/\S/)==-1)
	{
		alert("User Name should not be blank");
		document.getElementById('nickname').focus();
		return false;
	}
	if(document.getElementById('email').value.search(/\S/)==-1)
	{
		alert("Email should not be blank");
		document.getElementById('email').focus();
		return false;
	}
	
	var x = document.getElementById('email').value;
	var filter  =/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x)==false)
	{	
		alert("Invalid email");
		document.getElementById('email').focus();
		return false;
	}
	
	if(document.getElementById('password').value.search(/\S/)==-1)
	{
		alert("Password should not be blank");
		document.getElementById('password').focus();
		return false;
	}
	return true;
}
function loginvalidate()
{
	if(document.getElementById('loginemail').value.search(/\S/)==-1)
	{
		alert("Email should not be blank");
		document.getElementById('loginemail').focus();
		return false;
	}
	
	var x = document.getElementById('loginemail').value;
	var filter  =/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x)==false)
	{	
		alert("Invalid email");
		document.getElementById('loginemail').focus();
		return false;
	}
	
	if(document.getElementById('loginpassword').value.search(/\S/)==-1)
	{
		alert("Password should not be blank");
		document.getElementById('loginpassword').focus();
		return false;
	}
	return true;
}
</script>

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