Solved

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

Posted on 2013-06-06
11
400 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
ID: 39226535
Look on page 2
The javascript works
http://forums.asp.net/t/1130796.aspx/2/10
0
 

Author Comment

by:us1975mc
ID: 39226548
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
ID: 39226573
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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:us1975mc
ID: 39226580
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
ID: 39226603
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
 

Author Comment

by:us1975mc
ID: 39226646
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
ID: 39226663
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
ID: 39226665
forgot the _ at the end of the other side
0
 

Author Closing Comment

by:us1975mc
ID: 39226699
That was the ticket!

Thanks!
0
 
LVL 22

Expert Comment

by:plusone3055
ID: 39226713
Ooooh raaaah !
0
 

Author Comment

by:us1975mc
ID: 39226719
Semper Fi, Mac!
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

786 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