Hello,
There are two ways to do this task.
1 Through Regular Expression.
2 Write own code of JavaScript.
Here i am attaching a code snippet of JavaScript function which will automatically find the special character of given control id as input to it.
<script language="javascript" >
function CheckSpecialChar(id){
val=document.getElementById('id').value;
var splcharacter = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
for (var i = 0; i < val.length; i++) {
if (splcharacter.indexOf(val.charAt(i)) != -1) {
alert ("Special characters are not allowed.\n");
return false;
}
}
}
</script>
To call this function
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClientClick="CheckSpecialChar('TextBox1')" Text="Button" />
This is how it will validate the things.
Happy coding!!!!
Thanks
Rickeybglr, if this helps please login to Mark As Answer. | Alert Moderator