• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 183
  • Last Modified:

RegularExpressionValidator not working?

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
flynny
Asked:
flynny
1 Solution
 
Gary DavisDir Internet SvcsCommented:
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
 
flynnyAuthor Commented:
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

Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

Tackle projects and never again get stuck behind a technical roadblock.
Join Now