| | |
Validation
Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Mar 2009
Posts: 24
Reputation:
Solved Threads: 0
I am currently working on a project where i need check whether a date that is inputted is valid.
i know how to use this using repetitive if functions.
for example;
to check the month you do
if (month <1 || month >12)
Then to check the day which is my problem. Each month has a different amount of days in it. i can see how to do an if loop which then has an inner loop.
i.e
if (month == 1)
{
if (day <1 || day > 31)
Application.Exit
}
then i would go on and do that for all twelve months changing the if function where necessary. but is there a way to do this with arrays?
i know how to use this using repetitive if functions.
for example;
to check the month you do
if (month <1 || month >12)
Then to check the day which is my problem. Each month has a different amount of days in it. i can see how to do an if loop which then has an inner loop.
i.e
if (month == 1)
{
if (day <1 || day > 31)
Application.Exit
}
then i would go on and do that for all twelve months changing the if function where necessary. but is there a way to do this with arrays?
•
•
Join Date: Aug 2008
Posts: 1,735
Reputation:
Solved Threads: 186
Have you considered that you are reinventing the wheel?
Perhaps there is a function of the datetime variety that will do all this for you..
Perhaps there is a function of the datetime variety that will do all this for you..
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
•
•
Join Date: Mar 2008
Posts: 68
Reputation:
Solved Threads: 11
Try with DateTme.TryParse method .let me know it is working for u.
got solution ?, please mark the thread as Solved. Thanks & Regards,srikanth kadem
srikanthkadem@rediffmail.com
•
•
Join Date: Mar 2009
Posts: 24
Reputation:
Solved Threads: 0
•
•
•
•
Try with DateTme.TryParse method .let me know it is working for u.
ok that apears to be working. Thankyou
My final problem. How would i go about outputting the date that i have just validated. like this.
i put in 22/03/09 originally then the program works out whether the day needs a nd, st, rd or th at the end of it and then outputs like this;
22nd March, 2009
•
•
Join Date: Aug 2008
Posts: 1,735
Reputation:
Solved Threads: 186
I was trying to get you to look at the datetime functions for yourself to find the things like tryparse..
Perhaps you will now try and do a search on date time formats.
Perhaps you will now try and do a search on date time formats.
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
•
•
Join Date: Mar 2008
Posts: 68
Reputation:
Solved Threads: 11
i put in 22/03/09 originally then the program works out whether the day needs a nd, st, rd or th at the end of it and then outputs like this;
i did not get this words..can u explain indetails so that i can help u...
i did not get this words..can u explain indetails so that i can help u...
got solution ?, please mark the thread as Solved. Thanks & Regards,srikanth kadem
srikanthkadem@rediffmail.com
•
•
Join Date: Mar 2009
Posts: 24
Reputation:
Solved Threads: 0
ok I have now got the date inputted by the user in this format 12/12/1990 and have used the tryparse method to check for validity,
I now need to output that date as 12th December, 1990
i.e
Date:
Console.WriteLine("please insert a date")
date = Convert.ToString(Console.ReadLine())
String[] dateStrings = {date};
DateTime dateValue;
foreach (string dateString in dateStrings)
{
if (DateTime.TryParse(dateString, out dateValue))
goto output;
else
Console.WriteLine("\r\n {0}", date);
Console.WriteLine("\r\nError)
goto Date
}
I now want to output the date so that is outputs in a form like this 12th december 1990 instead of outputting as 12/12/09
I now need to output that date as 12th December, 1990
i.e
Date:
Console.WriteLine("please insert a date")
date = Convert.ToString(Console.ReadLine())
String[] dateStrings = {date};
DateTime dateValue;
foreach (string dateString in dateStrings)
{
if (DateTime.TryParse(dateString, out dateValue))
goto output;
else
Console.WriteLine("\r\n {0}", date);
Console.WriteLine("\r\nError)
goto Date
}
I now want to output the date so that is outputs in a form like this 12th december 1990 instead of outputting as 12/12/09
Check out this:
Flush goto's...
C# Syntax (Toggle Plain Text)
string dateString; DateTime dateValue; Console.WriteLine("please insert a date"); dateString =Console.ReadLine(); if (DateTime.TryParse(dateString, out dateValue)) { //it is a date } else { //error }
Flush goto's...
Last edited by ddanbe; Mar 3rd, 2009 at 6:51 pm.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Make love, no war. Cave ab homine unius libri.
Danny
Why do you do this? This is not C. Predeclaration makes code less readable.
•
•
Join Date: Mar 2008
Posts: 68
Reputation:
Solved Threads: 11
Hi Foxipj,
and u can play with this Tostring method as well for different formats.
C# Syntax (Toggle Plain Text)
dateValue.ToString("dd MMMM,yyyy"); use this line in if condition .where datevalue is datetime object in ur code.
got solution ?, please mark the thread as Solved. Thanks & Regards,srikanth kadem
srikanthkadem@rediffmail.com
![]() |
Similar Threads
- W3C Validation (HTML and CSS)
- .net validation/javascript conflict (ASP.NET)
Other Threads in the C# Forum
- Previous Thread: Trouble logging into sql server
- Next Thread: Create library in web
| Thread Tools | Search this Thread |
.net access algorithm array barchart bitmap box broadcast c# check checkbox client combobox control conversion csharp custom cyclethruopenforms data database datagrid datagridview dataset date/time datetime degrees development dll draganddrop drawing encryption enum event excel file finalyearproject form format forms function gdi+ getoutlookcontactusinfcsvfile globalization httpwebrequest image index input install installer java label list listbox mandelbrot math mono mouseclick mysql operator panel path photoshop picturebox pixelinversion post programming radians regex remote remoting richtextbox save server silverlight sleep socket sql sql-server statistics stream string table text textbox thread time timer timespan update usercontrol users validate validation visualstudio webbrowser wia windows winforms wpf xml






