How to use Regular Expression in C#

 How to Use Regular Expression in C#?

The Input value can be tested using “System.Text.RegularExpressions.Regex” class. Here is the sample code to verify whether the given input is numeric value or not:


bool bValid = IsValidValue(“<Input value>”);

protected bool IsValidValue(string val)
        {
            System.Text.RegularExpressions.Regex regx = new System.Text.RegularExpressions.Regex("[^0-9]");
            return !regx.IsMatch(val);           
        }

No comments:

Post a Comment