Hello All,
As per this article by Peter Blum, I am validating my date fields in dd/mm/yyyy format as follows:
BasePage.vb:
.aspx page:
My issue is that while validation passes for dd/mm/yyyy, it also passes for yyyy/mm/dd. In the background this "invalid" date is converted and saved in the database correctly, but our business users don't like the fact that they can enter a date in a format other than dd/mm/yyyy and the validation passes. I have played around with my InitializeCulture code (ie. removing the LongDatePattern, DateSeparator, MyBase call, etc.) but the screen still accepts the invalid date format. Is there anything I can do on the CultureInfo side, or will I have to manually validate the format of all dates? Keep in mind I'm using ASP.NET 2.0 without AJAX. Our site accomodates en-ca and fr-ca cultures, but the date input and display format is to remain as dd/mm/yyyy regardless of the language selection. The LongDatePattern is there because we transfer dates to and from the database in text format yyyy-mm-dd.
Any ideas?
Thanks,
Mike
As per this article by Peter Blum, I am validating my date fields in dd/mm/yyyy format as follows:
BasePage.vb:
Code:
Protected Overrides Sub InitializeCulture()
Dim setLang As String
setLang = Language & "-ca"
Dim newCulture As CultureInfo = CultureInfo.CreateSpecificCulture(setLang)
newCulture.DateTimeFormat.LongDatePattern = "yyyy-MM-dd"
newCulture.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy"
newCulture.DateTimeFormat.DateSeparator = "/"
Thread.CurrentThread.CurrentCulture = newCulture
Thread.CurrentThread.CurrentUICulture = newCulture
MyBase.InitializeCulture()
End Sub
.aspx page:
Code:
<asp:CompareValidator ID="cpvDOBDateFormat" runat="server" ControlToValidate="mdbDoB" CultureInvariantValues="true" Display="None" EnableClientScript="false" ErrorMessage="<%$ Resources: Translation, NotDate %>" Operator="DataTypeCheck" Type="Date" ValidationGroup="MemberProfile" EnableViewState="false" />
My issue is that while validation passes for dd/mm/yyyy, it also passes for yyyy/mm/dd. In the background this "invalid" date is converted and saved in the database correctly, but our business users don't like the fact that they can enter a date in a format other than dd/mm/yyyy and the validation passes. I have played around with my InitializeCulture code (ie. removing the LongDatePattern, DateSeparator, MyBase call, etc.) but the screen still accepts the invalid date format. Is there anything I can do on the CultureInfo side, or will I have to manually validate the format of all dates? Keep in mind I'm using ASP.NET 2.0 without AJAX. Our site accomodates en-ca and fr-ca cultures, but the date input and display format is to remain as dd/mm/yyyy regardless of the language selection. The LongDatePattern is there because we transfer dates to and from the database in text format yyyy-mm-dd.
Any ideas?
Thanks,
Mike