Solved

Special Characters in a text box - don't want them

Posted on 2013-06-06
11
398 Views
Last Modified: 2013-06-06
I have a web page that collects people’s names , addresses and so on.  There is a problem when someone enters their information and uses special characters in their name or addresses.  Such as Âlice Pâté.  I tried using a RegularExpressionValidator  with the ValidationExpression="^[a-zA-Z]{1,40}" and they can still get the special characters through.  

How can I prevent this.  I am using Visual Studio 2010 with Visual Basic on the aspx pages.

Any ideas?
<asp:RegularExpressionValidator ID="regexpName" runat="server"     
                                    ErrorMessage="This expression does not validate." 
                                    ControlToValidate="TextBox1"     
                                    ValidationExpression="^[a-zA-Z]{1,40}" />

Open in new window

0
Comment
Question by:us1975mc
  • 6
  • 5
11 Comments
 
LVL 22

Expert Comment

by:plusone3055
Comment Utility
Look on page 2
The javascript works
http://forums.asp.net/t/1130796.aspx/2/10
0
 

Author Comment

by:us1975mc
Comment Utility
plusone3055,

I currently have this code:
<script type="text/JavaScript">
    function valid(f) {
        !(/^[A-z;0-9]*$/i).test(f.value) ? f.value = f.value.replace(/[^A-z;0-9]/ig, '') : null;
    } 
</script>

 <asp:TextBox ID="TextBox1" runat="server" Text="" Width="400px"  onkeyup="valid(this)" onblur="valid(this)"/>

Open in new window


Problem here is it don't allow spaces.  How do I get a space in there?
0
 
LVL 22

Expert Comment

by:plusone3055
Comment Utility
try
<script type="text/JavaScript">
    function valid(f) {
        !(/^[A-z;0-9\d\s]*$/i).test(f.value) ? f.value = f.value.replace(/[^A-z;0-9]/ig, '') : null;
    }
</script>
0
 

Author Comment

by:us1975mc
Comment Utility
When I leave the textbox it takes all spaces out.  So if I placed in 'Alice Pate' as soon as I leave the textbox it changes to 'AlicePate'
0
 
LVL 22

Expert Comment

by:plusone3055
Comment Utility
try
<script type="text/JavaScript">
    function valid(f) {
        !(/^[A-z;0-9 _]*$/i).test(f.value) ? f.value = f.value.replace(/[^A-z;0-9]/ig, '') : null;
    }
</script>


 !(/^[A-z;0-9 _]*$/i).test

NOTE there is a "_"  before the closing bracket
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:us1975mc
Comment Utility
OK... Here is where it becomes strange.  It works fine if I don't give a special character.  If I enter 'Alice Pate' it gives 'Alice Pate' but is I enter 'Âlice Pàte' it gives 'AlicePate' it gives 'licePte'.  It still takes the space if a special character is added and it is fine if no special character is entered.
0
 
LVL 22

Expert Comment

by:plusone3055
Comment Utility
try
<script type="text/JavaScript">
    function valid(f) {
        !(/^[A-z;0-9 _]*$/i).test(f.value) ? f.value = f.value.replace(/[^A-z;0-9 _]/ig, '') : null;
    }
</script>
0
 
LVL 22

Accepted Solution

by:
plusone3055 earned 500 total points
Comment Utility
forgot the _ at the end of the other side
0
 

Author Closing Comment

by:us1975mc
Comment Utility
That was the ticket!

Thanks!
0
 
LVL 22

Expert Comment

by:plusone3055
Comment Utility
Ooooh raaaah !
0
 

Author Comment

by:us1975mc
Comment Utility
Semper Fi, Mac!
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now