Tuesday, July 04, 2006



Javascript code to Check Special Characters


function chkSpecialChar(formelement,text)
{
var msg='true';
var a=formelement.value;
var b=a.length;
var cha='`~!@#$%^&()+-[]{}/;:,<>.?';
var ch=cha.length;
var i,j;
for(i=0;i<ch;i++)
{
var ch1=cha.substring(i,i+1);
for(j=0;j<b;j++)
{
var a1=a.substring(j,j+1);
if(a1==ch1)
{
msg='Special Characters like ' +cha+ 'are not allowed in '+text;
alert(msg);
formelement.focus();
return false;
}
}
}
if (msg=='true')
{
return true;
}
}

0 Comments:

Post a Comment

<< Home