I'm trying to use required validation controls on two text boxes and tried using the following code: -
-
<asp:TextBox ID="starttimeInput" runat="server" Width="130px" Height="23px"></asp:TextBox>
-
<span class="style1">*</span> Start Time <asp:RequiredFieldValidator ValidationExpression="^([1-9]|1[0-2]|0[1-9]){1}(:[0-5][0-9][aApP][mM]){1}$"
-
ID="StartTimeValidator" runat="server"
-
ErrorMessage="You Must Supply Both a Start and an End Time"
-
ControlToValidate="starttimeInput"></asp:RequiredFieldValidator>
-
-
but I can still enter whatever I want into the text box. What I'm trying to check for is that users are entering a time in a valid format.
Can someone please point out to me where my expression may be wrong?
Thank you
Doug
7 10969
Hello,
you need Regular Expression validator to check on the input from user you can change validation expression on it's properties you can write this value on it
[0-2][0-3]:[0-5][0-9]
Try this i think it will help you.
Orked
Orked,
Yes sorry I was using the wrong kind of validator. My next question is in relation to this. I'm noticing that when I move from field to field that the validator checks for correct information in the text fields, is there a way that I can just have the validation run when a user presses the submit button rather than as they are typing?
Doug,
you can make the enable state to false in the properties of validator and change this state in the code behind the button you want to click on it like this - protected void Button1_Click(object sender, EventArgs e)
-
{
-
RegularExpressionValidator1.Enabled = true;
-
-
}
Orked
Ok last question on this subject,
I'm noticing that when I try to validate for time in one of my text boxes that I have the following regular expression:
ValidationExpression="^([0-1][0-9]|[2][0-3]):([0-5][0-9])$"
What that doesnt cover of course is if someone just enters in say
1:00 .. it returns an error.
What's the best way around accepting both and 1 and 2 characters for time?
Would it be something similar to date?
"^\d{1,2}\/\d{1,2}\/\d{4}$"
Thanks
Doug
Frinavale 9,735
Recognized Expert Moderator Expert
Your first regular expression will work with the addition of a "?". The ? indicates that there should be 0 or 1 repetitions of something.
So, it's pretty easy to modify your first regular expression to this so that it includes the cases where no leading 0 is provided: ^([0-1]?[1-9]|2[0-3]):[0-5][0-9]$
-Frinny
Ok so I had to do some more testing on this but I have the following 3 text boxes: -
<asp:TextBox ID="exceptiondateInput" runat="server" Width="130px" Height="23px"></asp:TextBox>
-
<span class="style1">*</span> Exception Date <asp:RegularExpressionValidator
-
ID="DateValidator" runat="server"
-
ControlToValidate="exceptiondateInput"
-
ValidationExpression="^\d{1,2}\/\d{1,2}\/\d{4}$"
-
ErrorMessage="Please Enter the Date Correctly"></asp:RegularExpressionValidator>
-
<br />
-
<br />
-
<br />
-
<asp:TextBox ID="starttimeInput" runat="server" Width="130px" Height="23px"></asp:TextBox>
-
<span class="style1">*</span> Start Time <asp:RegularExpressionValidator
-
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])?))$"
-
ID="StartTimeValidator" runat="server"
-
ErrorMessage="You Must Supply an Start Time"
-
ControlToValidate="starttimeInput"></asp:RegularExpressionValidator><br />
-
<br />
-
<br />
-
<asp:TextBox ID="endtimeInput" runat="server" Width="130px" Height="23px"></asp:TextBox>
-
<span class="style1">*</span> End Time <asp:RegularExpressionValidator
-
ID="EndTimeValidator" runat="server"
-
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])?))$"
-
ErrorMessage="You Must Supply an End Time"
-
ControlToValidate="endtimeInput"></asp:RegularExpressionValidator>
-
-
and if I hit my submit button here without entering anything in those textboxes, I don't get an error. What am I missing here?
RequiredFieldValidator : Will make sure the control is not blank.
ReqularExpressionValidator : Will make sure the input is Valid.
You Need Both Per TextBox..
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Megha Vishwanath |
last post by:
Hi,
We have an application where my clients may be at different timezones.
I need to validate time across the timezones with javascript. The date
object in JavaScript does not allow me to get...
|
by: Kenneth |
last post by:
Hello,
I'm having some serious problems debugging a script that I'm trying to make
work. I'm working on a form where a user can type in a time (in the format
of HH:MM), and another script...
|
by: simina |
last post by:
Hi...
I have an "appointments" page where the user should (or not
necessarily) choose a date and time for his appointment, from 6 combo
boxes:year, month, day, hour, minute and AM or PM, without...
|
by: Al |
last post by:
Hi,
I'm using an asp:textbox in a form and I want to use the
equivalent of the onkeyup event of a "normal" input text.
So far, it seems that all validator performs a check up
only on...
|
by: Chris |
last post by:
Hi,
I have a texbox in a webform that is supposed to hold Dates in a specific
format :
e.g. 20-12-2004
What is the best way to make sure that the entered data is in the correct
format ?
...
| |
by: R.A.M. |
last post by:
Hi,
Do you know if using asp: validators I can have validation text in
browser popup message box?
Thank you very much for your help.
/RAM/
|
by: menayah |
last post by:
Hi all,
Can i use vb validators to validate a date (MM/DD/YY) from a text box ? and also time (HH:MM am/pm)?
How to do this validation in a .net webform?
|
by: narend |
last post by:
I want to validation in time in 24:00 Hours format..
i am using in txtbox in html
|
by: DrSporkeh |
last post by:
Hai everyone, i need some help :o
basically im trying to set some validation rules for an 'employees' table.
firstly i've set it to you have to be 16 to work here under 'Date Of Birth'
...
|
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...
|
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...
| |
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...
|
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: 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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |