Regular expression for validating integer value

Regular expressions are a good way to validate text fields such as names, addresses, phone numbers, and other user information. You can use them to constrain input, apply formatting rules, and check lengths.
You can use the System.Text.RegularExpressions.Regex class for validate any input string for any specific format.
The following example will allow you to Input Integer Number only.


using System.Text.RegularExpressions;
public static bool CheckNumber(string strNumber)
            string MatchNumberPattern = "\d+";
            if (strNumber!= null) return Regex.IsMatch(strNumber, MatchNumberPattern );
            else return false;


Public Shared Function CheckNumber (ByVal strNumber As String) As Boolean
        Dim MatchNumberPattern As String = "\d+"       
  If strNumber IsNot Nothing Then
            Return Regex.IsMatch(strNumber , MatchNumberPattern)
            Return False
        End If
    End Function

More on Regular Expressions