Hai Saravanan,
Here is the rectified code within a HTML
<html><head>
<title>Scripting Test: by Murugan K Patham</title>
<script language="javascript">
<!--
function myfunc()
{
var myStr = new Array("~","!","#","$","%","^","&","*");
var ss = document.f1.un.value;
for(i=0;i<ss.length;i++)
{
myChr = ss.charAt(i);
alert("I got the character : " + myChr);
for(j=0; j<myStr.length;j++)
{
if(myChr == myStr[j])
{
alert("special character not allowed");
myChr = "";
break;
}
}
document.f1.ab.value=document.f1.ab.value+myChr;
}
}
//-->
</script>
</head>
<body>
<table border="2" cellpadding="8" bordercolor="red" align="center" font="courier">
<form name="f1">
<tr><td>
Enter Text:
<input type="text" name="un" maxlength="10" >
<input type="button" value="Test"
onclick="myfunc()">
<input type="text" name="ab" maxlength="10" >
</form>
</td></tr></table>
</body>
</html>
I just added more things for debugging purpose. Maybe you can cut short those and take
wharever you need.
Regds
Murugan K Patham
Ext 2712
>>> [EMAIL PROTECTED] 12/01 6:35 AM >>>
Hi everybody,
Can anybody help me how to validate special characters in Javascript.
It should not accept the characters which i used in array
declaration.In the below it shows some error.
Anybody can help me immediately!!!
thnx
sar.
My part of code is:
*********************
<script language=javascript>
function myfunc()
{
var str=new Array("~","!","#","$","%","^","&","*");
var ss=document.f1.un.value;
for(i=0;i<str.length;i++)
{
if(ss.substr(i,i+1).equals(str[i]))
{ alert("special character not allowed");
return(document.f1.un.value="");
}
}
}
<input type="text" name="un" maxlength="10" onblur="myfunc()">
_____________________________________________________________________________________
Get more from the Web. FREE MSN Explorer download : http://explorer.msn.com
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html