ali raza

C#, .Net ,Asp.net and my thoughts

Monthly Archives: September 2007

Quote of the day

Late to bed and late to wake will keep you long on money and short on mistakes.
  – Aaron McGruder

How do I find difference between two dates? In C#

DateTime startDate = new DateTime(2005, 2, 1, 3, 4, 12, 56);
// End date
DateTime endDate = new DateTime(2005, 12, 12, 4, 30, 45, 12
);
// Time span
TimeSpan diffDate = endDate.
Subtract ( startDate );
// Spit it out
Response.Write( “Time Difference: <br/> “
);
Response.Write
(diffDate.Days.ToString() + ” Days <br/>”
);
Response.Write
(diffDate.Hours.ToString() + ” Hours <br/>”
);
Response.Write
(diffDate.Minutes.ToString() + ” Minutes <br/>”
);
Response.Write
(diffDate.Seconds.ToString() + ” Seconds <br/> “
);
Response.Write
(diffDate.Milliseconds.ToString() + ” Milliseconds <br/>”);

I Believe I can fly

Very good song .Gives much hope

Most Wanted Regular Expressions

Just wanted to share this little collection of “Most Wanted Regular Expressions”

Regular expression examples for decimals input

Positive Integers — ^\d+$
Negative Integers — ^-\d+$
Integer — ^-{0,1}\d+$
Positive Number — ^\d*\.{0,1}\d+$
Negative Number — ^-\d*\.{0,1}\d+$
Positive Number or Negative Number – ^-{0,1}\d*\.{0,1}\d+$
Phone number — ^\+?[\d\s]{3,}$
Phone with code — ^\+?[\d\s]+\(?[\d\s]{10,}$
Year 1900-2099 — ^(19|20)[\d]{2,2}$
Date (dd mm yyyy, d/m/yyyy, etc.) — ^([1-9]|0[1-9]|[12][1-9]|3[01])\D([1-9]|0[1-9]|1[012])\D(19[0-9][0-9]|20[0-9][0-9])$
IP v4 — ^(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]){3}$

Regular expression examples for Alphabetic input

Personal Name — ^[\w\.\’]{2,}([\s][\w\.\’]{2,})+$
Username — ^[\w\d\_\.]{4,}$
Password at least 6 symbols — ^.{6,}$
Password or empty input — ^.{6,}$|^$
email — ^[\_]*([a-z0-9]+(\.|\_*)?)+@([a-z][a-z0-9\-]+(\.|\-*\.))+[a-z]{2,6}$
domain — ^([a-z][a-z0-9\-]+(\.|\-*\.))+[a-z]{2,6}$

Url —   http://(%5B\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?

Other regular expressions

Match no input — ^$
Match blank input — ^\s[\t]*$
Match New line — [\r\n]|$