AmrTamerTech/clsInput_Validation_Library-CPP
A C++ library for validating user input, including numeric range checks, date validation, and safe string reading. It ensures robust and error-free input handling in console applications.
๐ C++ Input Validation Library (clsInputValidate) โก
A lightweight and efficient C++ utility class designed to validate user input, ensuring data integrity and seamless error handling. This library provides robust number and date validation functions for console applications. ๐
๐ Project Overview
The clsInputValidate class helps developers ensure that user input meets required constraints, preventing invalid entries and enhancing program reliability. It includes functionalities such as:
โ๏ธ Numeric validation: Ensures input falls within a valid range.
โ๏ธ Date validation: Checks if a date is valid and falls within a given range.
โ๏ธ User input handling: Reads and processes numbers and strings safely.
โ๏ธ Error handling: Prevents incorrect inputs and prompts re-entry.
This class is designed for C++ console-based applications that require user input validation.
โจ Features
๐ข Numeric Validation
โ
IsNumberBetween(Number, From, To): Checks if a number is within a specified range.
โ
ReadNumber<T>(): Reads a number from user input and ensures validity.
โ
ReadNumberBetween<T>(From, To): Reads a number and validates it against a given range.
๐ Date Validation
โ
IsDateBetween(Date, DateFrom, DateTo): Verifies if a date is within a given range.
โ
IsValidDate(Date): Ensures that a given date is valid.
๐๏ธ User Input Handling
โ
ReadShortNumber(): Reads a short value from the user.
โ
ReadIntNumber(): Reads an int value from the user.
โ
ReadFloatNumber(): Reads a float value from the user.
โ
ReadDoubleNumber(): Reads a double value from the user.
โ
ReadString(): Reads and returns a string input from the user.
๐ How It Works
๐น Numeric Validation
- Uses template functions for flexible number validation.
- Ensures numbers fall within a valid range before returning them.
๐น User Input Handling
- Uses
cin,cin.clear(), andcin.ignore()to manage incorrect inputs. - Prevents crashes by properly handling invalid input formats.
๐น Date Handling
- Utilizes the clsDate class to compare and validate date values.
- Allows date range validation by checking if a date is between two others.
๐ Potential Enhancements
๐ Extended Error Handling: More detailed error messages for invalid input cases.
๐ Logging Support: Store incorrect attempts for debugging or analytics.
๐ Customizable Validation Rules: Allow developers to define custom validation rules dynamically.
๐ Localization Support: Multi-language error messages for international applications.
โ๏ธ Technologies Used
- Language: C++
- Concepts: Template functions, Input handling, Error validation
- Libraries:
<iostream>,<string>,<limits>
๐ฏ Learning Outcomes
โ๏ธ Robust input validation techniques
โ๏ธ Template function usage for flexible validation
โ๏ธ Error handling using input clearing and ignoring methods
โ๏ธ Date validation with structured logic
โ๏ธ Efficient and reusable C++ code
๐ Installation & Usage
๐ฅ Clone the Repository
git clone https://github.com/AmrTamerDev/clsInput_Validation_Library-CPP.git
cd clsInput_Validation_Library-CPP๐ License
This project is open-source. Feel free to fork, modify, and use it in your own C++ applications! ๐
๐ค Contributions
Contributions are welcome! If you have improvements or additional features to add, submit a Pull Request ๐