In C++ write validation function
A company requires that a valid customer numbers must be in the format of LLLNNNN ( three upper case letters followed by four digits). Please write a function called isValid that takes a string as an argument and returns if the string is a valid customer number.
source code:
*******************************************************************************/
#include <cctype>
#include <iostream>
#include <cstring>
using namespace std;
bool isValid(string str);
int main()
{
string str;
cout<<"Enter Customer number : ";
cin>>str;
if(isValid(str))
{
cout<<"Customer number is valid";
return 0;
}
cout<<"Customer
number is invalid";
return 0;
}
bool isValid(string
str)
{
if(str.length()==7)
{
if(isupper(str[0])
&&isupper(str[1])&&isupper(str[2])&&isdigit(str[3])&&
isdigit(str[4])&&isdigit(str[5])&&isdigit(str[6]))
return true;
else{
return false;
}
}
else{
return false;
}
}
if you have nay doubts ask me..
Get Answers For Free
Most questions answered within 1 hours.