Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to validate that a formatted string field has a non zero value? 1

Status
Not open for further replies.

jzman9

MIS
Aug 26, 2011
1
US
I am new to programming in C#. I am trying to develop a C# application using Visual Studio 2005. I wish to do some validation on a field titled "formattedString" as follows.
I tried to check that the field is numeric. I also want to check that the field does not have a value of Zero. Do you know how to
perform this validation using my existing code? Thanks.

arr1[i, 11] = "GROUP_FIELD_NAME:CpcsNo";
String h = reader.ReadElementContentAsString();
String formattedString = h.Substring(9, 6);
Int64 intTest = 0;
if (Int64.TryParse(formattedString, out intTest))
Console.WriteLine("Item is numeric");
else
Console.WriteLine("Item is not numeric");
 
int i;
if(int.TryParse(h, out i) == false)
{
not a number
}
else if(i == 0)
{
...
}
else
{
}


Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top