I’m using a TextBox to enter user’s name, here I want to validate that box only having alphabets which is starting with capital and continues with simple letters. For that I use the following code, even though its validating but if I enter a number after some alphabates it is not identifying that, please some one help me to find the problem.
if (!Regex.IsMatch(textBox3.Text, @"[a-zA-Z]"))
{
errorProvider2.SetError(textBox3, "Only use alphabates");
}
This will work. Satisfies all your conditions:
[A-Z]{1}– Matches the first letter to uppercase and only once.[a-z]+– Matches only lower case letters one or more times$– Marks the end of string, so numbers aren’t matched any more