Reputation: 2869
How do I check that string does not contain only alphabets in C#, and other allowed charaters are: dot: ".", whitespace, and comma: ","
Regex regex = new Regex("Regex Pattern");
bool result = regex.IsMatch(string);
if(result)
Messagebox.Show("String does not contain alphabets");
Examples:
ABC1 = false
ABC = true
ABC ABC = true
abc abc = true
A. B. ABC = true
The reason is because I have a field which contains people's names. Generally in these formats:
First
First Last
First Middle Last
F. M. Last
Title. F. M. Last
So, I want to validate those using regex.
Upvotes: 0
Views: 5406
Reputation: 73472
Try this
var regex = new Regex(@"(?i)^[a-z.,\s]+$");
bool res = regex.IsMatch(subject);
Upvotes: 3