wood burning stoves 2.0*
The moose likes HTML, CSS and JavaScript and the fly likes how to restrict user from entering special characters in a Textbox? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "how to restrict user from entering special characters in a Textbox?" Watch "how to restrict user from entering special characters in a Textbox?" New topic
Author

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

kapil shukla
Greenhorn

Joined: Jan 10, 2010
Posts: 4
how to restrict user from entering special characters in a Textbox?

please provide javascipt code snippet
Ashwini Kashyap
Ranch Hand

Joined: Aug 30, 2012
Posts: 90
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to restrict user from entering special characters in a Textbox?
 
Similar Threads
encryption of data shown in the address bar
Javascript help needed
Problem with encoding
Restricting 2 adjacent commas in text field
Regarding TextBox validation in Swing