473,406 Members | 2,352 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,406 software developers and data experts.

RegularExpressionValidator?

DC
I have this snippet:

<tr>
<td align="left">E-mail</td>
<td>
<asp:TextBox id="txtEmail" runat="server"
MaxLength="100"></asp:TextBox>&nbsp;
<asp:RegularExpressionValidator id="revEmail" runat="server"
ErrorMessage="Enter a valid e-mail address"
ControlToValidate="txtEmail"

ValidationExpression="\b[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z0-9._%-]{2,4}\b">
</asp:RegularExpressionValidator>
</td>
</tr>

My question is why this regular expression is not invoked if I leave the
textbox blank?
My understanding is blank entry is not met the requirement of that regular
expression.

Am I missing something here?

- DC
Nov 18 '05 #1
3 2002
DC wrote:
I have this snippet:

<tr>
<td align="left">E-mail</td>
<td>
<asp:TextBox id="txtEmail" runat="server"
MaxLength="100"></asp:TextBox>&nbsp;
<asp:RegularExpressionValidator id="revEmail" runat="server"
ErrorMessage="Enter a valid e-mail address"
ControlToValidate="txtEmail"

ValidationExpression="\b[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z0-9._%-]{2,4}\b">
</asp:RegularExpressionValidator>
</td>
</tr>

My question is why this regular expression is not invoked if I leave the
textbox blank?
My understanding is blank entry is not met the requirement of that regular
expression.

Am I missing something here?

- DC


Validators normally aren't enabled when something is left blank. Why
that decision was made (especially for regex validators) I'll never
know. Slap a RequiredFieldValidator on the field as well and all shall
function properly (if not with a little extra maintenance on your part).

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
Nov 18 '05 #2
I personally like the way Nicrosoft did that because you get two seperate
messages, one for [Required] and one for [Invalid].

"Craig Deelsnyder" <cdeelsny@NO_SPAM_4_MEyahoo.com> wrote in message
news:eR**************@TK2MSFTNGP10.phx.gbl...
DC wrote:
I have this snippet:

<tr>
<td align="left">E-mail</td>
<td>
<asp:TextBox id="txtEmail" runat="server"
MaxLength="100"></asp:TextBox>&nbsp;
<asp:RegularExpressionValidator id="revEmail" runat="server"
ErrorMessage="Enter a valid e-mail address"
ControlToValidate="txtEmail"

ValidationExpression="\b[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z0-9._%-]{2,4}\b"> </asp:RegularExpressionValidator>
</td>
</tr>

My question is why this regular expression is not invoked if I leave the
textbox blank?
My understanding is blank entry is not met the requirement of that regular expression.

Am I missing something here?

- DC


Validators normally aren't enabled when something is left blank. Why
that decision was made (especially for regex validators) I'll never
know. Slap a RequiredFieldValidator on the field as well and all shall
function properly (if not with a little extra maintenance on your part).

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET

Nov 18 '05 #3
It makes perfect sense to me, IF you enter a value, it will be validated.
It's not a RequiredRegularExpressionValidator after all, it's just a
RegularExpressionValidator.
"Craig Deelsnyder" <cdeelsny@NO_SPAM_4_MEyahoo.com> wrote in message
news:eR**************@TK2MSFTNGP10.phx.gbl...
DC wrote:
I have this snippet:

<tr>
<td align="left">E-mail</td>
<td>
<asp:TextBox id="txtEmail" runat="server"
MaxLength="100"></asp:TextBox>&nbsp;
<asp:RegularExpressionValidator id="revEmail" runat="server"
ErrorMessage="Enter a valid e-mail address"
ControlToValidate="txtEmail"

ValidationExpression="\b[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z0-9._%-]{2,4}\b"> </asp:RegularExpressionValidator>
</td>
</tr>

My question is why this regular expression is not invoked if I leave the
textbox blank?
My understanding is blank entry is not met the requirement of that regular expression.

Am I missing something here?

- DC


Validators normally aren't enabled when something is left blank. Why
that decision was made (especially for regex validators) I'll never
know. Slap a RequiredFieldValidator on the field as well and all shall
function properly (if not with a little extra maintenance on your part).

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET

Nov 18 '05 #4

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

Similar topics

0
by: Andy Eshtry | last post by:
I have a radio button list, a textbox representing SIN or EIN based on my radio button list selection so I put 2 regularexpressionvalidator to evaluate the value of textbox. EIN must be (for...
3
by: Ricardo Corsi P. Cesar | last post by:
Hi, i looking for example in asp.net (VB) to make the RegularExpressionValidator in runtime in my code behind. I found some similars codes, but nothing in VB.. thanks!
0
by: Matt Morris | last post by:
Hello: I have a RegularExpressionValidator control attached to a TextBox. I have the ValidationExpression property set to a very simple validation expression (\w+). The validation always fails...
3
by: tshad | last post by:
I have a RegularExpressionValidator that doesn't seem to work correctly if you don't enter anything. In the following, it works correctly if you have at least 1 character. If you just enter...
0
by: venkat Murthy | last post by:
Hi, I have 10 regularexpression validators in my datagrid. my datagrid looks like; first5controls | boundcolumn | next5controls. Regularexpressionvalidator for first five controls works...
1
by: franz | last post by:
does anybody tell me why it doesn't works?? in any case gg beame true thanks franz Dim y As RegularExpressionValidator = New RegularExpressionValidator y.ValidationExpression =...
1
by: John Yopp | last post by:
I'm trying to use a asp:RegularExpressionValidator to validate the strength of a password. When I test the regular expression with Regex.IsMatch, it works perfectly. However, when used within a...
4
by: simonZ | last post by:
I have RegularExpressionValidator which validate one text box. When my text box is validated on client I would like to do something else. Is there some client event of RegularExpressionValidator?...
4
by: =?Utf-8?B?Y3VyaW91cw==?= | last post by:
I am using a RegularExpressionValidator to validate a TextBox. I use "^?+(\.*)?$" to check for a real number. The control works fine as long as the user enters something in the TextBox; it does not...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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,...
0
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...

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.