http://www.pragmaticprogrammer.com/ppbook/extracts/rule_list.html
Archive for February, 2007
guideline for programmer
Posted in General, tagged Archive on February 17, 2007 | Leave a Comment »
IsDate in ASP.NET
Posted in C#.NET, tagged ASP, IsDate on February 9, 2007 | Leave a Comment »
public static bool IsDate(Object obj)
{
string strDate = obj.ToString();
try
{
DateTime dt = DateTime.Parse(strDate);
if((dt.Month!=System.DateTime.Now.Month) || (dt.Day<1&&dt.Day>31) || dt.Year!=System.DateTime.Now.Year)
return false;
else
return true;
}
catch
{
return false;
}
}
I have got another good solution form one forum according to my discussion with anotehr developer.
protected bool CheckDate(String date)
{
try
{
DateTime dt = DateTime.Parse(date); return true;
}
catch
{
return false;
}
}
IsNumeric in ASP.NET
Posted in C#.NET, tagged ASP, IsNumeric on February 9, 2007 | Leave a Comment »
public static bool IsNumeric(object value)
{
try
{
int i = Convert.ToInt32(value.ToString());
return true;
}
catch (FormatException)
{
return false;
}
}
isGuid in ASP.NET
Posted in C#.NET, tagged ASP, IsGuid on February 9, 2007 | Leave a Comment »
static bool isGuid(string guid)
{
bool isValid = false;
Regex re = new Regex(@”^({){0,1}[0-9a-fA-F]{8}-[0-9a-fA-F]{4}- [0-9a-fA-F]{4}-[0-9a-fA-F]{4}- [0-9a-fA-F]{12}(}){0,1}$”, RegexOptions.IgnoreCase);
if (re.IsMatch(guid))
{
isValid = true;
}
return isValid;
}

