C++/CLI Code Snippet - Validate Integer
C++/CLI code snippet to validate given integer. IsInteger function validate integer both positive and negative. Function return TRUE if valid integer found, if not function will return FALSE.
Bookmark:
C++/CLI Code Snippet - Validate Integer
This C++/CLI code snippet validate given integer values. This function uses regular expression to match string pattern to validate integer values.
bool IsInteger(System::String ^strNumber) { System::Text::RegularExpressions::Regex ^_RegexNotIntPattern = gcnew System::Text::RegularExpressions::Regex("[^0-9-]"); System::Text::RegularExpressions::Regex ^_RegexIntPattern = gcnew System::Text::RegularExpressions::Regex("^-[0-9]+$|^[0-9]+$"); return !_RegexNotIntPattern->IsMatch(strNumber) && _RegexIntPattern->IsMatch(strNumber); }
C++/CLI Keywords Used:
- Regex
- IsMatch
Code Snippet Information:
- Applies To: .Net, C++/CLI, Integer Validation, Regular Expression
- Programming Language : C++/CLI
External Resources: