473,325 Members | 2,442 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

simple textbox validation using regexvalidator

i am trying to validate a simple username textbox using RegularExpressionValidator:

TextBox tbUserName = new TextBox();
tbUserName.ID = "tbUserName";

string strPatternUserName = @"\W";
// i've tried using "\\W", "\w", "\\w","@\w", "/\\w", etc...
// but it always prints my error msg UNLESS the textbox is set to "".
// why does this not work?

RegularExpressionValidator rev = new RegularExpressionValidator();
rev.ControlToValidate = "tbUserName";
rev.Text = "Please enter a username";
rev.ValidationExpression = strPatternUserName;
rev.Display = ValidatorDisplay.Static;
rev.EnableClientScript = false;

please help, thank you.
Nov 16 '05 #1
2 8076
"live your lives" <ro*********@gmail.com> wrote in message news:18**************************@posting.google.c om...
i am trying to validate a simple username textbox using RegularExpressionValidator:

TextBox tbUserName = new TextBox();
tbUserName.ID = "tbUserName";

string strPatternUserName = @"\W";
// i've tried using "\\W", "\w", "\\w","@\w", "/\\w", etc...
// but it always prints my error msg UNLESS the textbox is set to "".
// why does this not work?


The following method returns true:

private static bool TestRegex()
{
bool match = false;
string test = @"\William";

Regex expr = new Regex("^(\\\\W)");
match = expr.IsMatch(test);

return match;
}

When in doubt, use more backslashes.

- carl
Nov 16 '05 #2
The problem with the regularexpressionvalidator control is that it expects a
string, not a RegEx expression. Since they are of different types I cannot
pass a RegEx object into the regularexpressionvalidator control.

Anyhow, I got it working similar to the way you did it. It is rather
strange that more backslashes are used. Ah well, at least it works right.

Thanks for your help.

"Vagabond Software" wrote:
"live your lives" <ro*********@gmail.com> wrote in message news:18**************************@posting.google.c om...
i am trying to validate a simple username textbox using RegularExpressionValidator:

TextBox tbUserName = new TextBox();
tbUserName.ID = "tbUserName";

string strPatternUserName = @"\W";
// i've tried using "\\W", "\w", "\\w","@\w", "/\\w", etc...
// but it always prints my error msg UNLESS the textbox is set to "".
// why does this not work?


The following method returns true:

private static bool TestRegex()
{
bool match = false;
string test = @"\William";

Regex expr = new Regex("^(\\\\W)");
match = expr.IsMatch(test);

return match;
}

When in doubt, use more backslashes.

- carl

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Pete | last post by:
Does anyone have a simple html vbscript or other type of snippet they can share that appends a record to a access database via ADO or DAO? I would like to allow users that don't have Microsoft...
0
by: R Reyes | last post by:
i am trying to validate a simple username textbox using RegularExpressionValidator: TextBox tbUserName = new TextBox(); tbUserName.ID = "tbUserName"; string strPatternUserName = @"\W"; //...
2
by: Hazzard | last post by:
I just realized that the code I inherited is using all asp.net server controls (ie. webform controls) and when I try to update textboxes on the client side, I lose the new value of the textbox when...
2
by: Pham Nguyen | last post by:
Has anyone seen an example of a textbox server control that has built-in client-side validation? I'd like to build a server control that extends the System.Web.UI.WebControls.TextBox class to allow...
4
by: hardcoded | last post by:
I have a textbox with TextMode set to MultiLine. I also have the MaxLength set to 255. This maxlength value seems to get ignored as the user can enter unlimited characters. Does the multiline...
8
by: Abul Hasan | last post by:
Hello everyone, I have placed simple validation through ErrorProvider Class on my textBoxes to check whether ther r empty or not Error Provider Class check and catches the error but it doesn't...
2
by: Alan Silver | last post by:
Hello, A couple fo questions about the easiest way to do some tasks. I'm sure both of these can be done with custom controls, but can they be done more easily with another validation control? ...
14
by: teddysnips | last post by:
WINDOWS FORMS I've a form that has a textbox that allows the user to enter a string. On the LostFocus event, the textbox formats the string into a preferred format. However, if the user...
4
by: HenrikL | last post by:
Hi. I have a textbox that have a binding on it with converter and validationrules. When a validation error ouccur the foreground of the textbox will change to red cause it has a style.triggers...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.