aspdotnet-suresh offers articles and tutorials,csharp dot net, articles and tutorials,VB.NET Articles,Gridview articles,code examples of 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

JavaScript - Remove Special Characters from Textbox

Feb 28, 2013

Here I will explain how to use JavaScript to remove special characters from textbox entered by 

In previous articles I explained JavaScript restrict user to enter only numbers, Watermark textbox in JavaScript, JavaScript validations for phone, email and many articles relating to
JavaScript, jQuery, Now I will explain how to use JavaScript to remove special characters from textbox entered by user.

To implement this we need to write the code like as shown below

<html xmlns="">
<title>Remove Special Characters from the Textbox using JavaScript</title>
<script language="javascript" type="text/javascript">
function RemoveSpecialChar(txtName) {
if (txtName.value != '' && txtName.value.match(/^[\w ]+$/) == null) {
txtName.value = txtName.value.replace(/[\W]/g, '');
<b>Enter Text:</b><input id="txtName"  type="text" onkeyup="javascript:RemoveSpecialChar(this)" />
Live Demo

For live demo check below example

Enter Text:

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest,, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email


Anonymous said...

Lorem Ipsum
after putting a special character...
spaces are removed...
i'm bad at cant solve myself...plz help

Atul Jadhav said...

hey Suresh...
this is not working if you drag the special character into textbox....
check it out.
and provide proper code.

Suresh Dasari said...

@Atul Jadhav...

Code is working fine for demo purpose i written code like above and i didn't put any restrictions and it's working fine. If you want don't want to allow drag and drop options you need to disable such kind of options by writing custom code.....

Constructions in madurai said...

can u explain it


Good Example

Constructions in madurai said...

how to do this in C# sir...
not in Javascript.

hermes said...

Thanks for helping me solve the special characters problem.

Anonymous said...

its good but i need for if we use

pradeep joshi said...

Dear sir,
Its working fine .I am getting a problem in my textbox text come from database and i want to change this text if i use special character then it removes all( backspace . ,) and combine whole text together.
please tell me how can i do this.

Give your Valuable Comments

Other Related Posts

© 2015 All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.