Solved

Military time

Posted on 2007-03-30
5
1,223 Views
Last Modified: 2007-12-19
I need a textbox that except military time only. Should I use datetime.now.tostring(format...? Thank you in advance.
For example right now is 9:10 pm - military time is  2110
0
Comment
Question by:VBdotnet2005
  • 3
  • 2
5 Comments
 
LVL 12

Expert Comment

by:Sinoj Sebastian
ID: 18828086
Try this

<asp:TextBox id="TBTime" style="Z-INDEX: 101; LEFT: 128px; POSITION: absolute; TOP: 152px" runat="server"></asp:TextBox>
                  <asp:RegularExpressionValidator id="RegularExpressionValidator1" style="Z-INDEX: 102; LEFT: 296px; POSITION: absolute; TOP: 152px"
                        runat="server" ErrorMessage="Invalid Time" ValidationExpression="(([01][0-9])|(2[0-3]))[0-5][0-9]" ControlToValidate="TBTime"></asp:RegularExpressionValidator>
                  <asp:Button id="BtnSubmit" style="Z-INDEX: 103; LEFT: 208px; POSITION: absolute; TOP: 192px"
                        runat="server" Text="Test" Width="72px"></asp:Button>
                  <asp:Label id="Label1" style="Z-INDEX: 104; LEFT: 56px; POSITION: absolute; TOP: 152px" runat="server">Enter time</asp:Label>

Tell me if you have any problem.
0
 

Author Comment

by:VBdotnet2005
ID: 18828579
If a user input 0651, for example, how can you tell whether it is am or pm, for those whom is not awared of it? Since it excepts it anyway.
0
 
LVL 12

Expert Comment

by:Sinoj Sebastian
ID: 18828685
I'm sorry, i don't understand what you are taking about.

0000 - 1159 is AM
1200 - 2359 is PM

try this
    Private Sub BtnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSubmit.Click
        Dim Time As Date
        Dim a As Char() = Trim(TBTime.Text).ToCharArray()
        TBTime.Text() = Date.Parse(a(0) + a(1) + ":" + a(2) + a(3)).ToShortTimeString
    End Sub
0
 

Author Comment

by:VBdotnet2005
ID: 18828751
Can you help me further? What is a user accidently input just a number? It is going to create an error, correct?
0
 
LVL 12

Accepted Solution

by:
Sinoj Sebastian earned 500 total points
ID: 18828914
I've used RegularExpressionValidator in the above code. If client is java script enabled, then if validation failed the page will not post back. You can use "if page.isvalid then" to confirm that user input is correct.

    Private Sub BtnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSubmit.Click
        If Page.IsValid Then
            Dim a As Char() = Trim(TBTime.Text).ToCharArray()
            TBTime.Text() = Date.Parse(a(0) + a(1) + ":" + a(2) + a(3)).ToShortTimeString
        End If
    End Sub

see the following link for further details
http://msdn2.microsoft.com/en-us/library/eahwtc9e.aspx

One problem with RegularExpressionValidator is that it will accept null string also. So, you may need  RequiredFieldValidator also.

Sorry
I'm late late. Tomorrow is sunday. I can give more detailed information day after tomorrow.
If you need further help, just drop a comment.

PS: I'm at GMT+05:30. Its 10PM now.
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question