To Trim the Empty space on both side

String.prototype.trim = function() {return this.replace(/^\s+\s+$/g,"");}

//Checking Blank Values

if (document.getElementById("txtName").value.trim()=="")
{
alert("Name Field can not be blank");
document.getElementById("txtName").focus();
return false;
}

//Checking AlphaNumeric Values

if (CheckKeyIsAlphanumerics(document.getElementById(txtName)))
return false;
else
return true;

function CheckKeyIsAlphanumerics(str)
{
var string = str.value.trim();
var iChars = "01234546789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
for (var i = 0; i lt; string.length; i++)
{
if (iChars.indexOf(string.charAt(i)) == -1)
return true;
}
return false;
}

To allow special characters in condition means add the special character in the iChars Variable.

//EmailValidation in the Textbox

if (isValidEMailID(document.getElementById("txtEmail")))
return true;
else
return false;


function isValidEMailID(oControl)
{
if(oControl.value != "")
{
if((/([A-Za-z]\w*)@(\[\d{1,3}(\.\d{1,3}){3}][A-Za-z]\w*(\.[A-Za-z]\w*)+)$/.test(oControl.value))==false)
{
alert("Invalid Email Format.");
oControl.value ="";
return false;
}

}
return true;
}

Pass the Control ID as Parameter for the Function.