Move validation methods to util namespace
This commit is contained in:
@@ -5,8 +5,6 @@ Date: 19-02-2026
|
||||
|
||||
#include <stdexcept>
|
||||
#include <iomanip>
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include "FoodDeliveryController.h"
|
||||
#include "Menu.h"
|
||||
#include "RestaurantOwnerMenu.h"
|
||||
@@ -22,6 +20,7 @@ Date: 19-02-2026
|
||||
#include "DeliveryAssignment.h"
|
||||
#include "inputHelper.h"
|
||||
#include "outputHelper.h"
|
||||
#include "Validator.h"
|
||||
#include "FileDatabase.h"
|
||||
|
||||
const std::string USERS_FILE = "User.txt";
|
||||
@@ -236,33 +235,6 @@ static deliveryAssignments::iterator selectDeliveryAssignmentFromList(deliveryAs
|
||||
return assignmentIterator;
|
||||
}
|
||||
|
||||
static bool isPhoneNumberValid(const std::string& phoneNumber) {
|
||||
if (phoneNumber.size() != 10)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return std::all_of(phoneNumber.begin(), phoneNumber.end(),
|
||||
[](char character)
|
||||
{
|
||||
return std::isdigit(character);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
static bool isEmailValid(const std::string& email) {
|
||||
size_t index = email.find('@');
|
||||
if (index == std::string::npos) return false;
|
||||
if (email.find('@', index + 1) != std::string::npos)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (index == 0 || index == email.size() - 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void FoodDeliveryController::loadUsers()
|
||||
{
|
||||
FileDatabase<User> userDatabase(USERS_FILE);
|
||||
@@ -574,14 +546,14 @@ void FoodDeliveryController::registerUser()
|
||||
util::readString(name);
|
||||
std::cout << "Enter Phone: ";
|
||||
util::readString(phone);
|
||||
if (!isPhoneNumberValid(phone))
|
||||
if (!util::isPhoneNumberValid(phone))
|
||||
{
|
||||
std::cout << "Phone Number is Invalid. Cannot Register User!\n";
|
||||
return;
|
||||
}
|
||||
std::cout << "Enter Email: ";
|
||||
util::readString(email);
|
||||
if (!isEmailValid(email))
|
||||
if (!util::isEmailValid(email))
|
||||
{
|
||||
std::cout << "Email ID is Invalid. Cannot Register User!\n";
|
||||
return;
|
||||
|
||||
@@ -141,6 +141,7 @@
|
||||
<ClCompile Include="RestaurantOwnerMenu.cpp" />
|
||||
<ClCompile Include="Trenser.FoodDeliveryApp.cpp" />
|
||||
<ClCompile Include="User.cpp" />
|
||||
<ClCompile Include="Validator.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Customer.h" />
|
||||
@@ -160,6 +161,7 @@
|
||||
<ClInclude Include="RestaurantOwner.h" />
|
||||
<ClInclude Include="RestaurantOwnerMenu.h" />
|
||||
<ClInclude Include="User.h" />
|
||||
<ClInclude Include="Validator.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Text Include="DeliveryAssignment.txt" />
|
||||
|
||||
+6
@@ -81,6 +81,9 @@
|
||||
<ClCompile Include="outputHelper.cpp">
|
||||
<Filter>Utility</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Validator.cpp">
|
||||
<Filter>Utility</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Customer.h">
|
||||
@@ -134,6 +137,9 @@
|
||||
<ClInclude Include="outputHelper.h">
|
||||
<Filter>Utility</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Validator.h">
|
||||
<Filter>Utility</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Text Include="DeliveryAssignment.txt">
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
Author: Joel Mathew Thomas
|
||||
Date: 25-02-2026
|
||||
*/
|
||||
|
||||
#include "Validator.h"
|
||||
|
||||
bool util::isPhoneNumberValid(const std::string& phoneNumber) {
|
||||
if (phoneNumber.size() != 10)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return std::all_of(phoneNumber.begin(), phoneNumber.end(),
|
||||
[](char character)
|
||||
{
|
||||
return std::isdigit(character);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
bool util::isEmailValid(const std::string& email) {
|
||||
size_t index = email.find('@');
|
||||
if (index == std::string::npos) return false;
|
||||
if (email.find('@', index + 1) != std::string::npos)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (index == 0 || index == email.size() - 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
Author: Joel Mathew Thomas
|
||||
Date: 25-02-2026
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include<string>
|
||||
#include<algorithm>
|
||||
#include<cctype>
|
||||
|
||||
namespace util
|
||||
{
|
||||
bool isPhoneNumberValid(const std::string&);
|
||||
bool isEmailValid(const std::string&);
|
||||
}
|
||||
Reference in New Issue
Block a user