?
Solved

Take special characters out of textbox

Posted on 2009-02-11
8
Medium Priority
?
485 Views
Last Modified: 2012-05-06
I can keep special characters out with the following method but it has one giant shortfall.
When you click in the textbox to change something it automatically send you to end of textbox after one letter and you cannot go back with the arrow keys.  How can I keep them from typing some special characters and allow them to press on back arrow or click in the middle of a typed textbox to edit existing information.
txtdescribe.Attributes.Add("onkeyup", "this.value=this.value.replace(/[^\w - \ . \ ? \ ,]+/,'')")

Open in new window

0
Comment
Question by:kdeutsch
  • 4
  • 4
8 Comments
 
LVL 16

Expert Comment

by:burakiewicz
ID: 23614669
try
txtdescribe.Attributes.Add("onblur", "this.value=this.value.replace(/[^\w - \ . \ ? \ ,]+/,'')")
 
0
 
LVL 16

Expert Comment

by:burakiewicz
ID: 23614680
this will replace the characters when then leave the textbox
0
 

Author Comment

by:kdeutsch
ID: 23614874
Hi,
This somewhat works.  Onw problem I am having is that when I put in a bunch a special characters spread through a sentence it does not get rid of them all, but if I click back in and then click out agian it keeps getting rid of them over multiple click in and outs.  Do I have something wrong with my syntax.
The only spcial charcters I want to allow them are the following.   . , ? - ! " &
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:kdeutsch
ID: 23614923
HI
Could you also expalin the syntax of this such as what (/{^\w) means.  Thanks
0
 
LVL 16

Expert Comment

by:burakiewicz
ID: 23615372
i think you need a g for global in there ill look up the syntax
0
 
LVL 16

Accepted Solution

by:
burakiewicz earned 1000 total points
ID: 23615434
try this
txtdescribe.Attributes.Add("onblur", "this.value=this.value.replace(/[^\w - \ . \ ? \ ,]+/g,'')")
also
the \w means
Matches any word character
here is a ref
http://regexlib.com/CheatSheet.aspx
0
 

Author Comment

by:kdeutsch
ID: 23616249
Got it, thanks for the information, the solution works great, better than what I had before and Now I know more about building them instead of just copying them.
0
 

Author Closing Comment

by:kdeutsch
ID: 31545707
Great solution better than I had
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Integration Management Part 2
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month14 days, 11 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question