473,607 Members | 2,674 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

RegEx Validation Control Bug??

I'm trying to have a form where a user has to enter a valid email address, and
I'm trying to use the RegEx Validation control to do that. The problem is that
when a user submits the form with a blank line, it is ACCEPTED even though it
does not pass the pattern match in the expression.

Another problem is that if there are leading spaces or trailing in a valid email
address, the expression fails.

Case 1:(blank) : PASSES (it shouldn't)
Case 2: jo*@sixpack.com : FAILS (leading spaces)
Case 3:jo*@sixpack.c om : FAILS (trailing spaces)
<form id="Form1" method="post" runat="server">
Enter your Email address:
<asp:TextBox id="txtEmail" runat="server"> </asp:TextBox>
<asp:RegularExp ressionValidato r id="valRegExEma il" runat="server"
ErrorMessage="E nter a valid email address"
ValidationExpre ssion="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
ControlToValida te="txtEmail">* </asp:RegularExpr essionValidator >
<br>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
<br>
<asp:Validation Summary id="ValidationS ummary1"
runat="server"> </asp:ValidationS ummary>
</form>

Nov 18 '05 #1
3 1947
I think in the documentation it says all validators accept empty string as
valid except the required validator.

"Mike" <do************ @boo.ya> wrote in message
news:80******** ***********@drn .newsguy.com...
I'm trying to have a form where a user has to enter a valid email address, and I'm trying to use the RegEx Validation control to do that. The problem is that when a user submits the form with a blank line, it is ACCEPTED even though it does not pass the pattern match in the expression.

Another problem is that if there are leading spaces or trailing in a valid email address, the expression fails.

Case 1:(blank) : PASSES (it shouldn't)
Case 2: jo*@sixpack.com : FAILS (leading spaces)
Case 3:jo*@sixpack.c om : FAILS (trailing spaces)
<form id="Form1" method="post" runat="server">
Enter your Email address:
<asp:TextBox id="txtEmail" runat="server"> </asp:TextBox>
<asp:RegularExp ressionValidato r id="valRegExEma il" runat="server"
ErrorMessage="E nter a valid email address"
ValidationExpre ssion="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
ControlToValida te="txtEmail">* </asp:RegularExpr essionValidator >
<br>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
<br>
<asp:Validation Summary id="ValidationS ummary1"
runat="server"> </asp:ValidationS ummary>
</form>

Nov 18 '05 #2
You need to use a required field validator in conjunction with a regular
expression validator. I'm guessing Microsoft have done it this way for
scenarios where fields only need to be validated if data is entered, though
it would have been nice if they could have added an option into the other
validators where you can force a field to be required.

As for the spaces problem... You could modify the regular expression to
allow leading or trailing spaces, and then trim the whitespace from the
string on the server side. Another way to do it, would be to write a
javascript function to trim the spaces client side, and update the textbox.

I.e.

<script language="javas cript">
<!--
function trimWhitespace( e)
{
e.value = e.value.trim();
}
</script>

Add this to the textbox, in the codebehind file:

txtEmail.Attrib utes.Add("onCha nge", "trimWhitespace (this)")
Hope this helps,

Mun

"Mike" <do************ @boo.ya> wrote in message
news:80******** ***********@drn .newsguy.com...
I'm trying to have a form where a user has to enter a valid email address, and I'm trying to use the RegEx Validation control to do that. The problem is that when a user submits the form with a blank line, it is ACCEPTED even though it does not pass the pattern match in the expression.

Another problem is that if there are leading spaces or trailing in a valid email address, the expression fails.

Case 1:(blank) : PASSES (it shouldn't)
Case 2: jo*@sixpack.com : FAILS (leading spaces)
Case 3:jo*@sixpack.c om : FAILS (trailing spaces)
<form id="Form1" method="post" runat="server">
Enter your Email address:
<asp:TextBox id="txtEmail" runat="server"> </asp:TextBox>
<asp:RegularExp ressionValidato r id="valRegExEma il" runat="server"
ErrorMessage="E nter a valid email address"
ValidationExpre ssion="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
ControlToValida te="txtEmail">* </asp:RegularExpr essionValidator >
<br>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
<br>
<asp:Validation Summary id="ValidationS ummary1"
runat="server"> </asp:ValidationS ummary>
</form>


Nov 18 '05 #3
You need to run a Required Field validation control first, then the regular
expression like this:

<form id="Form1" method="post" runat="server">
Enter your Email address:
<asp:TextBox id="email" runat="server" />
<asp:RequiredFi eldValidator
id="RequiredEma il"
runat="server"
ControlToValida te="email"
ErrorMessage="< br>* Email address is required"
Display="Dynami c"
/>
<asp:RegularExp ressionValidato r
id="RegExpEmail "
runat="server"
ControlToValida te="email"

ValidationExpre ssion="^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z][\w\.-]*[a-zA-Z0-
9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"
ErrorMessage="< br>* Email is not in a valid format"
Display="Dynami c"
/>
<br>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
<br>
</form>

"Mike" <do************ @boo.ya> wrote in message
news:80******** ***********@drn .newsguy.com...
I'm trying to have a form where a user has to enter a valid email address, and I'm trying to use the RegEx Validation control to do that. The problem is that when a user submits the form with a blank line, it is ACCEPTED even though it does not pass the pattern match in the expression.

Another problem is that if there are leading spaces or trailing in a valid email address, the expression fails.

Case 1:(blank) : PASSES (it shouldn't)
Case 2: jo*@sixpack.com : FAILS (leading spaces)
Case 3:jo*@sixpack.c om : FAILS (trailing spaces)
<form id="Form1" method="post" runat="server">
Enter your Email address:
<asp:TextBox id="txtEmail" runat="server"> </asp:TextBox>
<asp:RegularExp ressionValidato r id="valRegExEma il" runat="server"
ErrorMessage="E nter a valid email address"
ValidationExpre ssion="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
ControlToValida te="txtEmail">* </asp:RegularExpr essionValidator >
<br>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
<br>
<asp:Validation Summary id="ValidationS ummary1"
runat="server"> </asp:ValidationS ummary>
</form>

Nov 18 '05 #4

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

Similar topics

3
2399
by: Alan Pretre | last post by:
Can anyone help me figure out a regex pattern for the following input example: xxx:a=b,c=d,yyy:e=f,zzz:www:g=h,i=j,l=m I would want four matches from this: 1. xxx a=b,c=d 2. yyy e=f 3. zzz (empty) 4. www g=h,i=j,l=m
1
1718
by: Colin Reid | last post by:
Hey MS, here's an apparent problem in the base class library. I pulled the email validation pattern "^((*)*@(()+(*)*\.)+{2,9})" from http://regexlib.com. If I validate the email address "test@someverylongemailaddress.com" against it by just creating a RegEx and calling IsMatch it works fine, but if I create a schema defining a simple type restricting an xs:string by the regex pattern, it takes over full minute at 100% cpu to match....
5
318
by: Shaun Wilde | last post by:
When using the regular expression validator is there a way of failing a validation when you detect a match - I suppose a sort of anti-match. I want to detect certain things on user input and if they exist then fail client-side validation. An example would be detecting html input, a simple test of which would be to look for '<', but I would like to fail if this sequence is detected anywhere in a multiline string.
2
1576
by: Hailstorm | last post by:
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 "(()|())()" 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...
4
1359
by: | last post by:
Here is an interesting one. Running asp.net 2.0 beta 2. I have a regular expression used in a regex validator that works on the client side in Firefox but not in IE. Any ideas? IE always reports the field is invalid. The expression is: ^(?!\d)(?=.*\d)(?=.*)(?=.*)(?=.*).{8,25}$ If I enter "Test_Field1" Firefox considers it valid on client side, IE doesnt. Server side considers it valid too because when I submit the form in
3
3970
by: jab3 | last post by:
Hello. I"m new to this group, and to JavaScript in general, so please forgive me if I breach local etiquette. I'm trying to implement some client-side 'dynamic' validation on a form. I'm having a couple of problems, which I'll try to describe. But this e-mail will only reproduce one of them, in a "short" example. What I'm generally doing is having each form entry contained in a div, which as a label, an input with some event handlers,...
1
1944
by: Jim Dornbush | last post by:
Has anyone seen an updated regex expression from Microsoft for the email validation expression so that single quotes are allowed? I've been using the canned regex for emails, but recently been informed by a customer that the single quote is allowed as part of the email address (Mr. O'Leary). I prefer using the un-modified version from the framework, but will update my local code regardless.
11
1145
by: shapper | last post by:
Hello, I need to create a REGEX which accepts only phone numbers. The phone numbers start allways with 261, 21, 96 or 91 and have 7 numbers after it. Something like. 261 1223346, 21 2334456, etc. I tried the following but it is not working:
10
1863
by: bullockbefriending bard | last post by:
first, regex part: I am new to regexes and have come up with the following expression: ((1|),(1|)/){5}(1|),(1|) to exactly match strings which look like this: 1,2/3,4/5,6/7,8/9,10/11,12 i.e. 6 comma-delimited pairs of integer numbers separated by the
0
8049
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8463
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8128
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8322
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5471
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3953
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4013
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2461
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1574
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.