Say I have a date value contained within three fields:
Day
Month
Year
How would I validate this in an Xamarin app? I have read plenty of similar questions on here like this one: How to validate date input in 3 fields?. However, most appear to assume you are developing a website and can use JavaScript for this.
The ones that do show server side code advise using DateTime.TryParse (https://learn.microsoft.com/en-us/dotnet/api/system.datetime.tryparse?view=netframework-4.8). Is this the most appropriate option? The reason I ask is because:
1) DateTime.TryParse expects one parameter for the date instead of three
2) I have read other questions on here that advise again it because of regionalisation issues without really explaining why.
Is this still the most suitable way to do it - taken from here: validate 3 textfields representing date of birth:
DateTime D;
string CombinedDate=String.Format("{0}-{1}-{2}", YearField.Text, MonthField.Text, DayField.Text);
if(DateTime.TryParseExact(CombinedDate, "yyyy-M-d", DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None, out D)) {
// valid
} else {
// not valid
}
The code above was written in 2009. I remember reading another question on an Xamarin forum, which said that this is inelegant these days. Hence the reason for the question. Unfortunately I cannot now find this question to link to it.