Validate TextBOx in javascript

A simple Javascript function to validate Input values entered in TextBox will be as follows:-

//Calls when User Clicks on Ok in AddCriteria Div to validate Text Box Name
function ValidateGroupName()
{
Name = Document.getElementById("ctl00_ContentPlaceHolder1_txtCritGroupName").value;

NameSize=Name.length;
//Validation for Blank TextBox
if(NameSize==0)
{
alert("Group Name cannot be empty");
return false;
}

if(DescSize==0)
{
alert("Group Description cannot be empty");
return false;
}
//Validation for Group Name
//Validation for only Space Input
FlagName=true;
for(i=0;i {
if(Name.charAt(i)!=" ")
{
FlagName=false;
}
}
if(FlagName)
{
alert("Group Name can not cantain only spaces");
return false;
}
//Validation for Special Characters
else
{
for(i=0;i {
if(Name.charCodeAt(i)<48 || (Name.charCodeAt(i)>57 && Name.charCodeAt(i)<65) || (Name.charCodeAt(i)>90 && Name.charCodeAt(i)<97) || Name.charCodeAt(i)>122)
{
alert("Group Name can not contain special characters");
return false;
}
}
}

Comments

Popular posts from this blog

Weekend Gateway Trip - Shrivardhan

Cross Apply Incorrect syntax near '.'

Apply CSS Class based on Browser