Solved

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

Posted on 2013-06-06
11
401 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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with error in Query 2 31
Syntax Issue with SSIS module 26 105
How to share My.Settings in multiple application instances ? 7 31
abstract class C# 1 31
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

820 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