This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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
Regarding TextBox validation in Swing
Restricting 2 adjacent commas in text field
encryption of data shown in the address bar
Problem with encoding
Javascript help needed