c# - How to check the string formatting -


i learning simple console applications c# , have faced issue not manage solve. i've tried searching solution on stack overflow / internet, either don't know how search it, or there no answer i'm seeking.

situation: creating simple console app asks following things user: first name, family name, age.

every prompt (question) has been introduced user via following code:

system.console.write("what date of birth? "); string dob = system.console.readline(); 

i have made simple checker names, seeks if they're between 1-30 characters , if are, application writes results in text document.

question: how can check if date of birth has been written in following format: dd.mm.yyyy?

this return if it's valid date or not:

string dob = system.console.readline(); datetime dtresult; bool isvalid = datetime.tryparseexact(dob, "dd.mm.yyyy", system.globalization.cultureinfo.invariantculture, system.globalization.datetimestyles.none, out dtresult); 

but in case of e.g. january 1st can't detect month/day swap. result false if day > 12


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -