in my if statement i want to check to see if the user has entered a letter, how would i go about doing that since i cannot convert string to char.....and it seems C# doesnt let you do IsNumeric(string value) like in VB....any help with this
[code languge="C#"]
double y = 0; if (x.Length <= 8 || x.Length > 13){
MessageBox.Show("Your phone number does not contain the correct " +
"number of digits. Please format number " +
"as ###-###-####","Incorrect Number Format", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return x;}
[/code]

How to check for letter
Duque Vieira
If I were you I'd use regular expression to validate the phonenumber. IMHO it looks cleaner than iterating through the string. Have no idea which is to prefer performance-wise though.
Regex
.IsMatch(x, @"^\d{8-13}$");The above snippet will return true if x is a string of 8-13 numbers. Beware, I didn't test is ;)
/David
nanocity
Steve1999
overall, if you want to check if a string contains a letter:
foreach(Char curChar in theString)
{
if (!Char.IsLetter(curChar))
{
//current char is not a letter
}
}
in regards to your problem, you maybe better off using a masked textbox.
http://msdn2.microsoft.com/en-us/library/bbabas53.aspx
you could do this, but wouldnt recommend it:
foreach(Char curChar in theString)
{
if (!Char.IsNumber(curChar) && !curChar.ToString().Equals("-"))
{
//text entered isnt correct.
}
}
arogan
Rhodri Jenkins
Hi,
If you want to use the IsNumeric function from Visual Basic in your C# code for that
Jagdeep Sihota
sidhuvirgoster
akodad