Solved

RegularExpressionValidator not working?

Posted on 2014-03-01
2
157 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
2 Comments
 
LVL 18

Accepted Solution

by:
Gary Davis earned 500 total points
Comment Utility
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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
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!
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

772 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