Validate String For Positive Integer Values

Validate String For Positive Integer Values
A very simple way to validate a string for positive integer values using C# and regular expressions.
using System.Text.RegularExpressions;
 
Regex rxNums = new Regex(@"^\d+$"); // Any positive decimal
if (rxNums.IsMatch("4815162342"))
{
    MessageBox.Show("Numeric.");
}
else
{
    MessageBox.Show("Not numeric.");
}

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top