Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to restrict user from entering special characters in a Textbox?

 
kapil shukla
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to restrict user from entering special characters in a Textbox?

please provide javascipt code snippet
 
Ashwini Kashyap
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

You can restrict user from entering special characters by calling JS function like:

function validateSpecialCharacters()
{
var spclChars = "!@#$%^&*()"; // specify special characters
var content = document.getElementById("txtfieldId").value;
for (var i = 0; i < content.length; i++)
{
if (spclChars.indexOf(content.charAt(i)) != -1)
{
alert ("Special characters are not allowed.");
document.getElementById("txtfieldId").value = "";
return false;
}
}
}

Regards,
Ashwini Kashyap
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic