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

Regular Expression Validation

347 100+
I have the following three textboxes:

Expand|Select|Wrap|Line Numbers
  1. asp:TextBox ID="exceptiondateInput" runat="server" Width="130px" Height="23px"></asp:TextBox>
  2.         &nbsp; <span class="style1">*</span> Exception Date &nbsp;<asp:RegularExpressionValidator 
  3.             ID="DateValidator" runat="server" 
  4.             ControlToValidate="exceptiondateInput"
  5.             ValidationExpression="^\d{1,2}\/\d{1,2}\/\d{4}$" 
  6.             ErrorMessage="Please Enter the Date Correctly"></asp:RegularExpressionValidator>
  7.         <br />
  8.         <br />
  9.         <br />
  10.         <asp:TextBox ID="starttimeInput" runat="server" Width="130px" Height="23px"></asp:TextBox>
  11.         &nbsp; <span class="style1">*</span> Start Time &nbsp;<asp:RegularExpressionValidator
  12.             ValidationExpression="^((([0]?[1-9]|1[0-2])(:|\.)[0-5][0-9]((:|\.)[0-5][0-9])?( )?(AM|am|aM|Am|PM|pm|pM|Pm))|(([0]?[0-9]|1[0-9]|2[0-3])(:|\.)[0-5][0-9]((:|\.)[0-5][0-9])?))$"
  13.             ID="StartTimeValidator" runat="server" 
  14.             ErrorMessage="You Must Supply an Start Time" 
  15.             ControlToValidate="starttimeInput"></asp:RegularExpressionValidator><br />
  16.         <br />
  17.         <br />
  18.         <asp:TextBox ID="endtimeInput" runat="server" Width="130px" Height="23px"></asp:TextBox>
  19.         &nbsp; <span class="style1">*</span> End Time &nbsp;<asp:RegularExpressionValidator 
  20.             ID="EndTimeValidator" runat="server" 
  21.             ValidationExpression="^((([0]?[1-9]|1[0-2])(:|\.)[0-5][0-9]((:|\.)[0-5][0-9])?( )?(AM|am|aM|Am|PM|pm|pM|Pm))|(([0]?[0-9]|1[0-9]|2[0-3])(:|\.)[0-5][0-9]((:|\.)[0-5][0-9])?))$"
  22.             ErrorMessage="You Must Supply an End Time" 
  23.  
  24.  
and when I debug the page, if these textboxes are empty, I'm not getting an error back, I only get an error if I enter information that's in an incorrect format. Can anyone suggest why it's not giving me an error if the box is blank, when it should give me an error.

Thanks

Doug
Oct 8 '10 #1
2 1769
mzmishra
390 Expert 256MB
All validation controls, except the RequiredFieldValidator control, will pass validation if the input control pecified by the ControlToValidate property contains no text.
Use both requiredfield and regular expression validators
Oct 8 '10 #2
dougancil
347 100+
Mz Mishra,

So then a question would be how is the best way to do that so that the error messages still are presented in a way that they don't clutter the page. Would I use a validationSummary? or can it be done the way that I have it?
Oct 8 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: AGGoogle | last post by:
I might be doing something stupid here but I really need some help. Can someone please tell me why can't I get this xml to pass my validation when I use XmlValidatingReader? The XMLSpy seems to...
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: Nazir | last post by:
Hi I'm using a regular expression validator, but if spaces are entered, it bypasses the validation! I'm using ^{5,100}$
1
by: ra294 | last post by:
I want to use Regular Expression validation control to validate that the text that was entered into a text box includes only numbers (0-9) and it's size will be 6 or 7 chars only. What's the...
2
by: Coleen | last post by:
I can't remember the correct way to write a custom regular expression validator, and the help file for VB.net is not terribly helpful...it does not give any real world examples. I've got the main...
2
by: Ed Chiu | last post by:
Hi, I want to use regular expression validator to validate time in the pattern of 00:00 to 23:59 , what should the expression look like? TIA
2
by: Jon Natwick | last post by:
I am using the following script to validate e-mail address format. The problem I'm having however is that if I enter a long invalid string, like "123456789012345678901234567890", CPU process for...
1
by: clickon | last post by:
I am using a RegularExpressionValidator to validate against a range on specific values and it is behaving strangely. My validation expression is as follows ...
4
by: Brian Simmons | last post by:
Hi All, I've got a textbox where I want to make sure the person has entered at least 3 characters before submitting (it's like a partial name lookup type of query), so I don't want them to just...
1
by: neoupadhyay | last post by:
Why my regular expression validation is not working Friends I am using asp.net 1.1 and i try to apply regular expression validation. when i run it at my local host its work cool, but when i upload...
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
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
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
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,...
0
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...

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.