473,505 Members | 14,950 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Regex question

How can I control if "a textbox is empty or not" with regex validation? I
don't want to use required field validator because I have a masked textbox
control and it has "ValidationExpress" property.
For example, if I want to control if it's a time value, I use
"(([0-1][0-9])|([2][0-3]))[:]([0-5][0-9])" but it doesn't work when textbox
is empty. How can I solve this problem? I want user to fill this area.
And by the way, if I try to use a req field validator for this, my masked
textbox doesn't seem on validator's "Control To Validate" property although
it has been inherited from textbox control.
Waiting for your replies.

Sincerely
Nov 18 '05 #1
2 1564
I ran into this problem myself -- the validator does not check empty fields
(see below). I ended up inheriting the validator and changing the
client-side javascript to include my own validation function. The downside
is that I had to add that function to a custom WebUIValidation.js (ugh).

One thing you could do is do the validation on the postback, and then
trigger the validator (validator.IsValid = false).
Hope this helps,
Sam Fields

excerpt from WebUIValidation.js ...

function RegularExpressionValidatorEvaluateIsValid(val) {
var value = ValidatorGetValue(val.controltovalidate);

#### if length=0 arbitrary "yes" #####
if (ValidatorTrim(value).length == 0)
return true;
var rx = new RegExp(val.validationexpression);
var matches = rx.exec(value);
return (matches != null && value == matches[0]);
}
"Hailstorm" <nomail@> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
How can I control if "a textbox is empty or not" with regex validation? I
don't want to use required field validator because I have a masked textbox
control and it has "ValidationExpress" property.
For example, if I want to control if it's a time value, I use
"(([0-1][0-9])|([2][0-3]))[:]([0-5][0-9])" but it doesn't work when textbox is empty. How can I solve this problem? I want user to fill this area.
And by the way, if I try to use a req field validator for this, my masked
textbox doesn't seem on validator's "Control To Validate" property although it has been inherited from textbox control.
Waiting for your replies.

Sincerely

Nov 18 '05 #2
If you would rather get a regex validator that already has the ability to
support blank textboxes instead of writing the code yourself, I can offer a
solution.
I rewrote ASP.NET validation to address all kinds of limitations including
this one. "Professional Validation And More"
(http://www.peterblum.com/vam/home.aspx) includes 22 validators. Its
RegexValidator has a property to allow blank text. All of these validators
support client side validation on many more browsers than the original
validators which are limited to DHTML browsers.

Even if you don't want a third party solution, you may benefit from knowing
the limitations to ASP.NET validation as you plan your site. I put together
a list: http://www.peterblum.com/vam/valmain.aspx.

--- Peter Blum
www.PeterBlum.com
Email: PL****@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
"Hailstorm" <nomail@> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
How can I control if "a textbox is empty or not" with regex validation? I
don't want to use required field validator because I have a masked textbox
control and it has "ValidationExpress" property.
For example, if I want to control if it's a time value, I use
"(([0-1][0-9])|([2][0-3]))[:]([0-5][0-9])" but it doesn't work when textbox is empty. How can I solve this problem? I want user to fill this area.
And by the way, if I try to use a req field validator for this, my masked
textbox doesn't seem on validator's "Control To Validate" property although it has been inherited from textbox control.
Waiting for your replies.

Sincerely

Nov 18 '05 #3

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

Similar topics

4
4345
by: engwar1 | last post by:
Not sure where to ask this. Please suggest another newsgroup if this isn't the best place for this question. I'm new to both vb.net and regex. I need a regular expression that will validate what...
4
9703
by: aevans1108 | last post by:
expanding this message to microsoft.public.dotnet.xml Greetings Please direct me to the right group if this is an inappropriate place to post this question. Thanks. I want to format a...
2
3411
by: Tim Conner | last post by:
Hi, Thanks to Peter, Chris and Steven who answered my previous answer about regex to split a string. Actually, it was as easy as create a regex with the pattern "/*-+()," and most of my string...
6
396
by: Du Dang | last post by:
Text: ===================== <script1> ***stuff A </script1> ***more stuff <script2> ***stuff B
17
3941
by: clintonG | last post by:
I'm using an .aspx tool I found at but as nice as the interface is I think I need to consider using others. Some can generate C# I understand. Your preferences please... <%= Clinton Gallagher ...
5
5077
by: Chris | last post by:
How Do I use the following auto-generated code from The Regulator? '------------------------------------------------------------------------------ ' <autogenerated> ' This code was generated...
6
5851
by: Martin Evans | last post by:
Sorry, yet another REGEX question. I've been struggling with trying to get a regular expression to do the following example in Python: Search and replace all instances of "sleeping" with "dead"....
7
2565
by: Extremest | last post by:
I am using this regex. static Regex paranthesis = new Regex("(\\d*/\\d*)", RegexOptions.IgnoreCase); it should find everything between parenthesis that have some numbers onyl then a forward...
6
4190
by: Phil Barber | last post by:
I am using Regex to validate a file name. I have everything I need except I would like the dot(.) in the filename only to appear once. My question is it possible to allow one instance of character...
6
2053
by: | last post by:
Hi all, Sorry for the lengthy post but as I learned I should post concise-and-complete code. So the code belows shows that the execution of ValidateAddress consumes a lot of time. In the test...
0
7216
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7098
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7303
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7018
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7471
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5613
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5028
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4699
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
407
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.