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.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jorge L FernandezPosted Nov 9, 2009, 2:03 PM
Kirtan just answered your question.
Jorge L FernandezPosted Nov 9, 2009, 2:01 PM
string theValue = "MyString.";
bool matched = Regex.Match(theValue ,@"^[a-zA-Z]*\.$").Success
This should work fine
Kirtan PatelPosted Nov 9, 2009, 2:00 PM
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 !!");
}
}
Sam HobbsPosted Nov 9, 2009, 1:51 PM