Code: Select all
if(IsNumeric(textBox1.Text) == true)
{
// your convert code goes here
}
else
{
// your error message goes here
}
snippet made by the great edward. I take no credit.
Moderator: Coders of Rage
Code: Select all
if(IsNumeric(textBox1.Text) == true)
{
// your convert code goes here
}
else
{
// your error message goes here
}
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!
actually..that's not correct. .NET doesn't have an IsNumeric() method built into the framework. That's an old VB method that didn't make it in the jump to .NET.Keevu wrote:put something like "please input number" where the your error message goes where comment is at.Code: Select all
if(IsNumeric(textBox1.Text) == true) { // your convert code goes here } else { // your error message goes here }
snippet made by the great edward. I take no credit.
Code: Select all
int number = 0;
if (int.TryParse(textBox1.Text, out number))
{
//do something with number
}
else
{
//scream at the user, cuz that's not a number!
}
trufun202 wrote:actually..that's not correct. .NET doesn't have an IsNumeric() method built into the framework. That's an old VB method that didn't make it in the jump to .NET.Keevu wrote:put something like "please input number" where the your error message goes where comment is at.Code: Select all
if(IsNumeric(textBox1.Text) == true) { // your convert code goes here } else { // your error message goes here }
snippet made by the great edward. I take no credit.
I would recommend the following:
EDIT: Or, a more user friendly option may be to use an asp:RegularExpressionValidator to validate the number on the client side.Code: Select all
int number = 0; if (int.TryParse(textBox1.Text, out number)) { //do something with number } else { //scream at the user, cuz that's not a number! }