C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Data Validation


Posted Date: 29 Oct 2007    Resource Type: Code Snippets    Category: Validations

Posted By: santhosh       Member Level: Gold
Rating:     Points: 10



This example shows you how to validate a string against an integer, decimal, date or null values.
This code uses C#.



// Method to validate a string against integer value
// Input : a string containing integer value
// Output : true if the string contains integer; otherwise false



public bool ValidateInt(string val)
{
try
{
int i = int.Parse(val);
return(true);
}
catch(Exception)
{
return(false);
}
}




// Method to validate a string against null values
// Input : a string containing data
// Output : true if the string contains data; otherwise false


public bool ValidateText(string val)
{
val = val.Trim();
if (val == "" || val == null)
return (false);
else return (true);
}


// Method to validate a string against date
// Input : a string containing date
// Output : true if the string contains date; otherwise false

public bool ValidateDate(string val)
{

try
{
DateTime d = DateTime.Parse(val);
return (true);
}
catch (Exception)
{
return (false);
}

}



// Method to validate a string against decimal value
// Input : a string containing decimal value
// Output : true if the string contains decimal; otherwise false


public bool ValidateDecimal(string val)
{
try
{
float val1 = float.Parse(val);
return true;
}
catch(Exception )
{
return (false);
}

}





Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Text Box Validation for allowing only alpha and special characters of @ and _ in VB.Net
Previous Resource: Javascript function for validating Date fields
Return to Discussion Resource Index
Post New Resource
Category: Validations


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

silicone halloween mask

Contact Us    Privacy Policy    Terms Of Use