Last post Jan 03, 2018 01:01 PM by 0belix
Jan 03, 2018 12:38 PM|0belix|LINK
I'm attempting to validate a date that needs to be in the dd/MM/yyyy format using compareValidator.
I've followed every tip i could find on google to make this work. I've set the Culture and UICulture both on the page directive and on the web.config to en-GB but still it won't accept a date like 29/9/1974 nor 29/09/1974... but as soon as i input 9/29/1974,
it no longer returns false.
I need the date to be on the dd/MM/yyyy format, and i'm getting really frustrated as all the solutions i could find on the web either point me to a regex that will allow dates like 30th of February, or 31 of April, which is not acceptable since those dates
Here's my current validator:
<asp:CompareValidator CssClass="regularExpression" ID="cv_birthDate" ControlToValidate="birthDate" Operator="DataTypeCheck" Type="Date" CultureInvariantValues="true" Text="*" ErrorMessage="Please check if the birthdate inserted is valid" runat="server" ValidationGroup="val_registration" />
Any suggestions on how to overcome this issue?
Jan 03, 2018 01:01 PM|0belix|LINK
I've managed to make it work.
I was setting the Culture and UI Culture derived from the URL culture property (i use routing), which only states "en" and not "en-GB". This was causing the culture to always be set to "en-US" instead of the "en-GB" set on the web.config and page directive,
which in turn was causing the validator to always validate the US data format and not the UK date format. I guess the default for "en" is "en-US"...