?
Solved

correct date and time in textbox

Posted on 2005-03-29
8
Medium Priority
?
191 Views
Last Modified: 2010-04-07
Urgent

Hi

Whats the best way to do the following?

ensure that the user always enters the date and time correctly into a textbox.

dd/mm/yy hh:mm
25/02/05 14:23

validation
textbox mask
or something else

im thinking textbox mask is the best but dont know how to do that in asp.net

can anyone help?
0
Comment
Question by:narmi2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 11

Expert Comment

by:sachiek
ID: 13650858
The simplest approach would just be to create a method that returns a bool and tries to parse the text into a DateTime object. The DateTime.Parse(string) method should work just fine, and if the text is not in the correct format you will catch the exception thrown. Once you have the exception, you can throw error

I would also either go with the validation events, or the TextChanged event to try and parse out the text into a DateTime object.

0
 
LVL 11

Expert Comment

by:sachiek
ID: 13650881
You can modify culture according to your need.

System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo("en-GB");
DateTime a = DateTime.Parse(txt1.text,culture,System.Globalization.DateTimeStyles.NoCurrentDateDefault);

Now use try catch and validate it.

0
 
LVL 1

Author Comment

by:narmi2
ID: 13650941
I was hoping for something more client side, which does not have to do a round trip to the server.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Expert Comment

by:brdrok
ID: 13651778
have you considered using a pop up calendar?

btnCalendar.Attributes["onClick"]=@"javascript:calendar_window=window.open('Calendar.aspx?formname=frmAddOrders.txtDueOn', 'calendar_window', 'width=200, height=200'); calendar_window.focus(); return true;";

assuming that you have a web form called calendar.aspx

0
 
LVL 7

Expert Comment

by:brdrok
ID: 13651780
and a button called btnCalendar

0
 
LVL 7

Expert Comment

by:brdrok
ID: 13651782
my fault...didn't see that you needed the time as well...in that case a calendar probably wouldn't do much good.
0
 
LVL 7

Accepted Solution

by:
ayha1999 earned 2000 total points
ID: 13652709
Hi,

use this regularexpression for RegularExpression validaotr.

(?n:^(?=\d)((?<day>31(?!(.0?[2469]|11))|30(?!.0?2)|29(?(.0?2
)(?=.{3,4}(1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|(1
6|[2468][048]|[3579][26])00))|0?[1-9]|1\d|2[0-8])(?<sep>[/.-
])(?<month>0?[1-9]|1[012])\2(?<year>(1[6-9]|[2-9]\d)\d{2})(?
:(?=\x20\d)\x20|$))?(?<time>((0?[1-9]|1[012])(:[0-5]\d){0,2}
(?i:\ [AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$)

hope this helps.

ayha
0
 
LVL 7

Assisted Solution

by:ayha1999
ayha1999 earned 2000 total points
ID: 13652856
Hi again,

pls. visit the following site where u can;t find regularexpression meeting ur requirements.

http://www.regexlib.com/Default.aspx

ayha
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

741 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