RegEx Force Upper Case

By James J

Allow users only to enter upper case string & validate it by regex...

private void button1_Click(object sender, EventArgs e)
{
          
System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"^[A-Z]$");
            
if (regex.IsMatch(textBox1.Text))
            {
                 MessageBox.
Show("Value is correct.");
            }
            
else
            {
                 MessageBox.
Show("Value is not correct.");
            }
}

RegEx Force Upper Case  (929 Views)