Pergunta

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.

Foi útil?

Solução

Regular expression is ok. Negate predicate:

if (! pattern.IsMatch(txtCustName.Text))
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top