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
Solved

RegularExpressionValidator not working?

Posted on 2014-03-01
2
160 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
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

How our DevOps Teams Maximize Uptime

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

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Latest thoughts on C# utilizing Mono on Linux vs .NET on Windows? 5 64
Syntax Issue with SSIS module 26 104
VB.NET Textbox input validation 4 40
Visual Studio npm 1 12
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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
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…

860 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