C++/CLI Code Snippet - Validate whole number

C++/CLI Code Snippet - Validate whole number

C++/CLI Code Snippet - Validate whole number

C++/CLI code snippet to validate given whole number. IsWholeNumber function validates positive integers with zero inclusive. Function return TRUE if valid whole number found, if not function will return FALSE.

Bookmark:

C++/CLI Code Snippet - Validate whole number

This C++/CLI code snippet validate given whole number. This function uses regular expression to match string pattern to validate whole number.

bool IsWholeNumber(System::String ^strNumber)
{
    System::Text::RegularExpressions::Regex ^_RegexNotWholePattern = gcnew System::Text::RegularExpressions::Regex("[^0-9]");
    return !_RegexNotWholePattern->IsMatch(strNumber);
}


C++/CLI Keywords Used:

  • Regex
  • IsMatch

Code Snippet Information:

  • Applies To: .Net, C++/CLI, Whole Number Validation, Regular Expression
  • Programming Language : C++/CLI

External Resources:

Leave a comment