0

Hi
I want the user to only type letters (a-z simple or capital) in the Name textbox.If the user types any other character(like numbers or commas,semicolons) I want to show a message.How can I check for it(in C#)?
Thnx in Advance

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by Dimansu
1

Place this below code into button click if you want to check or to textchanged event.

bool isStrictMatch = false;
            string patternStrict = @"^([a-zA-Z]+)$";
            Regex reStrict = new Regex(patternStrict);
            if (txtSecond.Text.Trim() != string.Empty)
            {
                isStrictMatch = reStrict.IsMatch(txtSecond.Text.Trim());
                if (!isStrictMatch)
                    MessageBox.Show("Please use alphabetics", "Validation", MessageBoxButtons.OK);
            }
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.