Wednesday, October 29, 2008

ASP.NET Regular Expression for date format

In ASP.Net Many times required to Validate Date Fromat Enter in Control.in Regular Expression Following RE used to Validate Date Format.

dd/mm/yyyy Format (optional mm,optional dd)
([1-9]0[1-9][12][0-9]3[01])[- /.]([1-9]0[1-9]1[012])[- /.][0-9]{4}$

mm/dd/yyyy (optional mm,optional dd)
^([1-9]0[1-9]1[012])[- /.]([1-9]0[1-9][12][0-9]3[01])[- /.][0-9]{4}$

mm/dd/yyyy (Exact Format)
^([01]\d)/([0-3]\d)/(\d{4})$

Good Luck

Monday, August 11, 2008

Get DayNames in a given Culture

Sometimes we may need to have the day names in a week for a given culture. With ASP.NET CultureInfo class you can loop through the DateTimeFormat.DayNames and get them. Here is the example of it

using System.Globalization;
CultureInfo ci = new CultureInfo("ar-ae");
// gets the day names of arabic, arab emirates
foreach (string day in ci.DateTimeFormat.DayNames)
Response.Write(day + " ");

Depending on the culture you want, you can get the CultureInfo reference for that corresponding culture. The DateTimeFormat also provides other values like month names, first day of week etc.,

Good Luck

Preventing Duplicate Record Insertion on Page Refresh

I have found a good article on preventing the duplicate record insertion on page refresh by Terri Mortan.
Check the article here http://aspalliance.com/687