?
Solved

RegularExpressionValidator not working?

Posted on 2014-03-01
2
Medium Priority
?
170 Views
Last Modified: 2014-03-10
Hi all,

I have the following code;

    <asp:TextBox ID="UsernameTextbox" runat="server" MaxLength="10" ></asp:TextBox>

    <asp:RegularExpressionValidator id="UsernameRegularExpressionValidator" runat="server" 
        ValidationExpression="[0-9a-zA-Z]" 
        ControlToValidate="UsernameTextbox" />

Open in new window


I want to restrict special chars from being entered to my textbox. However, it is still allowing me to enter these? I only want the user to be able to enter alphanumeric values.

Now I am capturing the .keyup() method using Jquery, coudl this be causing a problem?
0
Comment
Question by:flynny
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 18

Accepted Solution

by:
Gary Davis earned 2000 total points
ID: 39897915
See http://msdn.microsoft.com/en-us/library/ff650303.aspx

Your expression will validate true as long as there is at least one alphanumeric.

You need to validate true only if all characters are alphanumeric:

    ValidationExpression="^[0-9a-zA-Z]*$"

Gary Davis
0
 

Author Comment

by:flynny
ID: 39898406
Hi Gary

Many thanks for the reply and the Regex update.

I've been reading up on the validator. Does the validator check input as the user types (I.e. Restrict client side?) or when I submit serverside?

The reason I ask is I am performing a Ajax (using jquery) call to a webmethod which he is the db to see if the username exists. Therefore at the moment it is allowing user to type the illegal char and sending to the webmethod?

Will I need to do a jquery check on the key up event and double check in the webmethod?
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

801 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