Date Validation
-
how can i validate date input from user, i accepts that date in to a CEdit derived control, i want to check whether the user enter the in right format or not ( my required format is DD/MM/YY). any idea ? Thanks in advance Ninety-eight percent of the thrill comes from knowing that the thing you designed works, and works almost the way you expected it would. If that happens, part of you is in that machine.
-
how can i validate date input from user, i accepts that date in to a CEdit derived control, i want to check whether the user enter the in right format or not ( my required format is DD/MM/YY). any idea ? Thanks in advance Ninety-eight percent of the thrill comes from knowing that the thing you designed works, and works almost the way you expected it would. If that happens, part of you is in that machine.
Use
CDateTimeCtrl
. It can be validated.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
-
how can i validate date input from user, i accepts that date in to a CEdit derived control, i want to check whether the user enter the in right format or not ( my required format is DD/MM/YY). any idea ? Thanks in advance Ninety-eight percent of the thrill comes from knowing that the thing you designed works, and works almost the way you expected it would. If that happens, part of you is in that machine.
Doing it "old school", you can use a call to
sscanf(...)
, which was designed for scanning a formatted string. For example, if you would build a string usingprintf(...)
with a format string of"%02d/%02d/%02d"
, you would scan that string back with that same format string, and check the return value ofsscanf(...)
to make sure you scanned out three tokens/values. That would help you verify the format, but not the data... For example, scanning"99/88/77"
would be successful, even though it is an invalid date. Peace! -=- James
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
DeleteFXPFiles & CheckFavorites -
Doing it "old school", you can use a call to
sscanf(...)
, which was designed for scanning a formatted string. For example, if you would build a string usingprintf(...)
with a format string of"%02d/%02d/%02d"
, you would scan that string back with that same format string, and check the return value ofsscanf(...)
to make sure you scanned out three tokens/values. That would help you verify the format, but not the data... For example, scanning"99/88/77"
would be successful, even though it is an invalid date. Peace! -=- James
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
DeleteFXPFiles & CheckFavoritesA nice article on codeproject site, "editable date time control", using date time edit control and programmer is validating the date based on format, if you check his code, you may get idea about date validation from edit control. Anand