I have the following code in a function to check if string 'datestr' is in the correct format (dd/mm/yyyy):
if (sscanf(datestr, "%d/%d/%d", &day, &month, &year) != 3) return NULL;
While it works with a correct formatted string like "02/10/2015" it also works with a string like "2/10/2015" which is not correct formatted as day and month must be 2 digits long each and year 4 digits long. Is there a way I can check this within the sscanf function? Or do I have to check it before with an if condition like the following?
if (!(strlen(datestr) == 10 && isdigit(datestr[0]) && isdigit(datestr[1]) && ...)) return NULL;
Thank you!