Need help with regular expressions
i want to validate a string which may contains only alphabets and may end with only a single (.) dot
example
mystring.
4 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Sam HobbsRank #107 · 20.5K reputationPosted Nov 9, 2009, 8:51 AM EST
Kirtan PatelRank #292 · 8.6K reputationPosted Nov 9, 2009, 9:00 AM EST
Here is Code according to your requirement .
dont forget to mark "Do you like this answer check box " please :)
private void button1_Click(object sender, EventArgs e)
{
string str ="Your String Here To Validate.";
Regex rex = new Regex(@"[a-zA-Z ]*\.{0,1}");
if (rex.IsMatch(str) == true)
{
MessageBox.Show("String is Valid !!");
}
else
{
MessageBox.Show("String is Not valid !!");
}
}
Jorge L FernandezRank #7,688 · 236 reputationPosted Nov 9, 2009, 9:01 AM EST
string theValue = "MyString.";
bool matched = Regex.Match(theValue ,@"^[a-zA-Z]*\.$").Success
This should work fine
Jorge L FernandezRank #7,688 · 236 reputationPosted Nov 9, 2009, 9:03 AM EST
Kirtan just answered your question.