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. π
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.
β
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.
β
IsDateBetween(Date, DateFrom, DateTo): Verifies if a date is within a given range.
β
IsValidDate(Date): Ensures that a given date is valid.
β
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.
- Uses template functions for flexible number validation.
- Ensures numbers fall within a valid range before returning them.
- Uses
cin,cin.clear(), andcin.ignore()to manage incorrect inputs. - Prevents crashes by properly handling invalid input formats.
- Utilizes the clsDate class to compare and validate date values.
- Allows date range validation by checking if a date is between two others.
π 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.
- Language: C++
- Concepts: Template functions, Input handling, Error validation
- Libraries:
<iostream>,<string>,<limits>
βοΈ 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
git clone https://github.com/AmrTamerDev/clsInput_Validation_Library-CPP.git
cd clsInput_Validation_Library-CPPThis project is open-source. Feel free to fork, modify, and use it in your own C++ applications! π
Contributions are welcome! If you have improvements or additional features to add, submit a Pull Request π