zimmer9
asked on
In an ASP.NET application in C#, how could this app evaluate the string input and send an error message back to the user that the length is wrong or in wrong format?
I am maintaining an ASP.NET C# application that has a date field named "dtCreated" in a database table with the format varchar(10). This field has values in the format MM/DD/YYYY. For ex: 11/30/2016.
How could this application evaluate the string that is input and send an error message back to the user if the input is NOT
A) in the format MM/dd/yyyy OR
B) 10 characters in length because they left out a leading 0 for a month between 1 and 9 or a date between 1 and 9
for ex: they input 1/01/2017 or 01/1/2017
How could this application evaluate the string that is input and send an error message back to the user if the input is NOT
A) in the format MM/dd/yyyy OR
B) 10 characters in length because they left out a leading 0 for a month between 1 and 9 or a date between 1 and 9
for ex: they input 1/01/2017 or 01/1/2017
There are all kinds of problems with using a character field to hold a date. Since you are "maintaining" an existing app and database, you probably aren't free to change the database to a datetime column (but you REALLY should if you can). However, you should be able to change the form field where the user is entering the value to an appropriate date format. If you can do that, you've got some of the potential problems solved... just convert the date entered to the desired string format and stick it in your database.
ASKER
Could you elaborate on how I would deal with the challenge of handling the string of a date entered?
Sure, check iyt this MSDN page. It contains a very descriptive example. https://msdn.microsoft.com/en-us/library/w2sa9yss.aspx
This link might be better... http://net-informations.com/q/faq/stringdate.html
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.