Question

here is my code o check whether a string contain any other character than a-z OR A-Z.

        Regex  pattern = new Regex("^[a-zA-Z]+$");
        if (pattern.IsMatch(txtCustName.Text))
        {

            MessageBox.Show("Name contains some Invalid Characters");

            txtCustName.Focus();
        }

It still showing error msg even I'm typing he correct string.

Was it helpful?

Solution

Regular expression is ok. Negate predicate:

if (! pattern.IsMatch(txtCustName.Text))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top