I’m using the code below to determine if the value entered into textBoxAddress.Text is a number (fax number) or an email address. My isNumber test below won’t work if the fax number has spaces so I’m trying to remove all white space with the Regex, the whitespace isn’t being removed. Can you spot my problem?
Thank you.
string faxOrEmail = textBoxAddress.Text;
faxOrEmail = Regex.Replace(faxOrEmail, @"\s+", " "); //<---Regex
bool testForFax = IsNumber(faxOrEmail);
if (testForFax == true)
{
//send fax
MessageBox.Show(faxOrEmail);
}
else
{
backgroundWorker1.RunWorkerAsync(); //Send Email
}
static bool IsNumber(string value)
{
// Return true if this is a number.
int number1;
return int.TryParse(value, out number1);
}
You are replacing one or more spaces with a single space.
This doesn’t remove dashes, and your IsNumber method isn’t necessary.