Check special characters at the beginning of the text

Blessybaby
Posted by Blessybaby under JavaScript category on | Views : 2825
var ctrl=document.getElementsByTagName("input");
//TextBox Validation
for (i=0;i<ctrl.length;i++)
{
if(ctrl[i].type=="text")
{
if (document.getElementById(ctrl[i].id).value.length>0)
{
var iChars = "!@#$%^&*()+=-[]\\\';,/{}|\":<>?";
if (iChars.indexOf(document.getElementById(ctrl[i].id).value.charAt(0)) != -1)
{
alert ("Special characters are not allowed at the beginning of the text.\n Please remove them and try again.");
document.getElementById(ctrl[i].id).select();
return false;
}
}
}
}

Comments or Responses

Login to post response