I wanted to do a simple date validation to disallowed string from entering when prompt. Pls guide me. Tks.

Eg,
"Enter the publish date in DD/MM/YYYY : ghghjb
"Sorry, pls enter in DD/MM/YYYY"
"Enter the publish date in DD/MM/YYYY :

# include<iostream>
# include<string>

using namespace std;

class date
{
	public : char publish_date[11];
};

date list[2];

void printbook();

int main()
{
	
	char ch;
	for(int i = 0; i < 2; i++)
	{
		
		cout << "Enter the publish date in DD/MM/YYYY : ";
		cin >> list[i].publish_date;
	
		
	}

	cout << "Press 'L' to view the list of books...";
	cin >> ch;

	if(ch == 'l' || ch == 'L')
	{
		printbook();
	}
}



void printbook()
{
	for(int i = 0; i < 2; i++)
	{
		cout << "Book Publishing date : " << list[i].publish_date << endl << endl;
	}
}

What you may do is to accept the user input as string, and then verify it before you put it in your date variable. If the input string is invalid, keep looping until you get the right format. Your should not use cin>>list.publish_date right away but rather put it in another string for validation first.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.