Validating the date format

I want to restrict my date format to dd/mm/yyyy type.. with a specific range for date, month and year. Although, I have put the constraints for range but I am unable to restrict the format. What I want is that if the user after entering the date and month.. presses 'enter' key or 'space' key.. instead of the year value, it should show an error ant take the input again. Similarly for date and month.

Here is my code.. please help


cout << "Enter the date " ;
dat: gotoxy(30, 11);
cin >> xdd;
if (xdd==0)
return;
else if (xdd<1||xdd>31)
{ a.clear(5,23);
gotoxy(5,23);
cout<<"Enter a valid date";
a.clear(30,11);
goto dat; }

gotoxy(32, 11);
cout << "/";
mon: gotoxy(33, 11);
cin >> xmm;
if (xmm==0)
return;
else if (xmm<1||xmm>12)
{ a.clear(5,23);
gotoxy(5,23);
cout<<"Enter a valid month (1-12)";
a.clear(33,11);
goto mon; }

gotoxy(35, 11);
cout << "/";
year: gotoxy(36, 11);
cin >> xyy;
if (xyy==0)
return;
else if (xyy<1000||xyy>4000)
{ a.clear(5,23);
gotoxy(5,23);
cout<<"Enter a valid year (in four digits)";
a.clear(36,11);
goto year; }


my program include graphics and I am working on turbo c. Please help. :/
Last edited on
If you want to force the user to write dd/mm/yyyy in one line, read the whole line with getline, then use a stringstream to extract and check each number.

When posting code, use [code][/code] tags.
Last edited on
Topic archived. No new replies allowed.