Solved

Military time

Posted on 2007-03-30
5
1,214 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

760 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now