Hello everyone, I am trying to validate the user input by using isalpha and isdigit. The input is supposed to consist of the following format: AB123456. I was going to check for AB using isalpha and 123456 using isdigit. The input needs to consist of two letters and six numbers. I was also going to assign the input to an array so I could check it.
This is my first time using these, so I'm not too sure how to implement it into my code. I know how to validate an input that is all characters or all digits, but not if it's a combination of the two.
Here is what I got. It doesn't compile. Can someone point me in the right direction? Thank you:
Code:
void searchID ()
{
//local variable
string userInput;
int count = 0;
do
{
cout << endl << "Enter ID number of student to find (or X to exit): ";
cin >> userInput;
while((isalpha(userInput[0])) || (isalpha(userInput[1])) || (isdigit(userInput[2])) || (isdigit(userInput[3])) || (isdigit(userInput[4])) || (isdigit(userInput[5])) || (isdigit(userInput[6])) || (isdigit(userInput[7])))
{
cout << "Invalid entry. Try again." << endl;
cin >> userInput;
}
if (userInput == 'X')
{
cout << "Goodbye!" << endl << endl;
system ("PAUSE");
}
}while (userInput != 'X')
return;
}